Hi Govert,
I'm wondering why a workbook (with a macro) remains in the VBA editor after I manually unload it.
Here's what I've done
1. Created a simple com server that has a routine called HelloWorld. Here's the code:
'*************************************************************************************************************
Imports ExcelDna.Integration
Imports ExcelDna.ComInterop
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop
Public Class AddIn
Implements IExcelAddIn
Public Sub AutoOpen() Implements IExcelAddIn.AutoOpen
ComServer.DllRegisterServer()
End Sub
Public Sub AutoClose() Implements IExcelAddIn.AutoClose
ComServer.DllUnregisterServer()
End Sub
End Class
<ComVisible(True)>
<ClassInterface(ClassInterfaceType.AutoDispatch)>
<ProgId("ReleaseApp")>
Public Class Apps
Public Sub HelloWorld()
Dim xxlapp As Excel.Application = ExcelDnaUtil.Application
Dim strChk As String
strChk = xxlapp.ActiveSheet.cells(1, 1).text
If strChk = "" Then
xxlapp.ActiveSheet.cells(1, 1).value = "Hello World"
Else
xxlapp.ActiveSheet.cells(1, 1).value = ""
End If
End Sub
End Class
'*********************************************************************************************************************************
2. Loaded a workbook CallHelloWorld.xls that contains a HelloWorld macro. Here's the VBA code:
'**********************************************
Sub HelloWorld()
Dim lib As Object
Set lib = CreateObject("ReleaseApp")
lib.HelloWorld
Set lib = Nothing
End Sub
'*********************************************************
3. Run the HelloWorld Macro
4. Unload the CallHelloWorld.xls from Excel
5. Although the workbook has been unloaded, the worksheets and macros are still visible in the VBA editor.
After I unload the workbook the workbook still appears in the VBA editor, so there's an object that hasn't been cleared properly. After looking into this, the line of code that causes the workbook from unloading properly is when the xlapp object is set to the ExcelDNAUtils.application object.
Is there something wrong with my code? Is there a method I can run so that after using DNA, the workbooks unload from Excel properly? I'm running large analyses that crash intermittently and want to eliminate any memory leaks I may have. And this is the first one I've found.
I've run the app in Excel 2003, 2010, and 2016. Same results in any of the versions of Excel.
Thanks in Advance,
Paul
.