Reference: Q0032
Article Last Modified on 31-August-2006
I have an XLA and an XLL that work together. How can I open and close the XLL from the XLA?
Application.RegisterXLL.Application.ExecuteExcel4Macro to
invoke the XLM4 macro UNREGISTER.CXllApp::UnregisterFunctions() in your CXllApp::OnXllClose()
event handler.The Visual Basic for Applications code below shows how to open and close an XLL. Note that you should pass the XLL's entire path and name when opening it, but only the file name when you close it.
Option Explicit
Const xllName = "RegTest.xll"
Const filePath = "C:\Files\RegTest\Debug\" & xllName
Public Sub DoIt()
On Error GoTo ErrorHandler
Application.RegisterXLL filePath
Exit Sub
ErrorHandler:
Debug.Print Err.Number, Err.Description
End Sub
Public Sub UndoIt()
On Error GoTo ErrorHandler
Application.ExecuteExcel4Macro "UNREGISTER(""" & xllName & """)"
Exit Sub
ErrorHandler:
Debug.Print Err.Number, Err.Description
End Sub
The code below shows how to ensure that all the add-in functions registered by
the XLL are removed from Excel's Formula Wizard. Add a call to CXllApp::UnregisterFunctions()
after all other termination code has run.
void CRegTestApp::OnXllClose()
{
// Delete menu
m_menu.Destroy();
// Ensure that all functions are removed from Excel's Formula Wizard
UnregisterFunctions();
}
FAQ #0029: How can I open an XLL from another XLL