View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Stephen Bullen Stephen Bullen is offline
external usenet poster
 
Posts: 67
Default Closed workbook remains in memory.

Hi Kent,

After the add-in opens, updates and closes the workbook. The workbook is
still listed in the VBAProject window. Still in memory.
It is closing the Excel Workbooks but not destroying them. I am using the
following syntax.


This is symptomatic of your VB code continuing to have a reference to the
workbook in a variable somewhere.

Using the following code.
Private Sub Main
Dim xlApp As New Excel.Application
xlApp.Workbooks.Open "C:\myaddin.xla"
xlApp.Visible = True
xlApp.Run "MyModuleName"
xlApp.Quit
Set xlApp = Nothing
End Sub


You don't explicitly close the workbook here, so Excel may be waiting for a
'Save Changes' prompt. How about:

Private Sub Main
Dim xlApp As Excel.Application
Dim xlWkBk As Excel.Workbook

Set xlApp = New Excel.Application
Set xlWkBk = xlApp.Workbooks.Open("C:\myaddin.xla")
xlApp.Visible = True
xlApp.Run "MyModuleName"

xlWkBk.Close False
Set xlWkBk = Nothing

xlApp.Quit
Set xlApp = Nothing
End Sub

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.co.uk