Closing Excel
Hi,
I've written a routine that opens an existing Excel workbook in a new Excel application instance. However, in a different routine, I wish to close the workbook and quit the application. The code seems to fire off ok but I noticed that the other Excel instance sticks around in the Windows Task Manager. Can anyone help?
Thanks,
joey
Here's the code:
Private app As Excel.Application
Private wb As Excel.Workbook
Private Sub CommandButton1_Click()
Dim str As String
str = ThisWorkbook.ActiveSheet.Range("PATH")
' open the workbook
Set app = New Excel.Application
app.Visible = False
oldStatusBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
Application.StatusBar = "Please be patient..."
Set wb = app.Workbooks.Open(str, ReadOnly)
Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar
End Sub
Private Sub CommandButton3_Click()
' On Error Resume Next
wb.Close False
Set wb = Nothing
app.Quit
Set app = Nothing
End Sub
|