Close application when workbook is closed 
Author Message
 Close application when workbook is closed

I need some help on this one.  I'm trying to write a
script in VB that will close the Excel application when
the workbook is closed.  But, I only want it to run if the
application was opened with the script.  If the user has
other Excel workbooks open, then I don't want the script
to close the App.  I'm pretty close, I think.  I've got it
to open the application and close it based on the
variables listed above.  However, it doesn't wait for the
workbook to close.  Here's what I've got so far.

Function IsExcelRunning() As Boolean
    Dim xlApp As Excel.Application
    On Error Resume Next
    Set xlApp = GetObject(, "Excel.Application")
    IsExcelRunning = (Err.Number = 0)
    Set xlApp = Nothing
    Err.Clear
End Function
Private Sub Command96_Click()
If Me!Frame35 = 1 Then
     strInput = InputBox("ENTER THE PASSWORD: ")
If strInput <> "PERCEPTA" Then
     MsgBox "Sorry, you've entered an incorrect password."
Else
    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim ExcelRunning As Boolean

    ExcelRunning = IsExcelRunning()
    If Not ExcelRunning Then
        Set xlApp = CreateObject("Excel.Application")
    Else
        Set xlApp = GetObject(, "Excel.Application")
    End If

     xlApp.Visible = True
     xlApp.Workbooks.Open ("\\usmlbfp1\library\change mgt
logs\axz\axz change log.xls")
End If

{THIS IS WHERE I NEED HELP.  I DON'T WANT IT TO JUST OPEN
AND CLOSE.  I NEED THE CODE TO MAKE THE APPLICATION CLOSE
ONLY AFTER THE WORKBOOK IS MANUALLY SHUT DOWN BY THE USER}

    'If we started the instance, our code uses the
    'Quit method to close the instance
    If Not ExcelRunning Then xlApp.Quit
    Set xlBook = Nothing
    Set xlApp = Nothing
End If
End Sub



Tue, 28 Sep 2004 02:52:16 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Closing 1 workbook closes all workbooks

2. Application hangs after closing workbook or quitting application.

3. Excel closing after closing workbook (OLE automation)

4. Errors when closing a workbook using top right close (x) button

5. Help: Closing other .xls files automatically when workbook closed

6. Closing a Workbook Closes Excel, Process Persists

7. Errors when closing a workbook using top right close (x) button

8. When closing a Word 2002 document the application closes

9. VBA Project does not close when workbook is closed

10. closing a workbook/application


 
Powered by phpBB® Forum Software © phpBB Group