Reference: Q0029
Article Last Modified on 11-June-2006
My XLL needs to be sure that another XLL is open. How can I make sure that an XLL is opened?
Use the xlfRegister macro function to open an XLL and register all
its methods. This macro will open the XLL properly, just as if it was opened
through File/Open or Tools/Add-ins. The correct place to call the
macro is probably during the handling of OnXllOpenEx() in your own
XLL.
Note that this technique can only be used within a macro function or an event handler, not from within a worksheet function. It is therefore not possible to apply a "load-on-demand" strategy.
BOOL CBootstrapApp::OnXllOpenEx()
{
// Calculate the full path of the bootstrapped XLL, which
// is assumed to be in the same directory as this XLL.
CString strXll2 = GetXllName();
int iSplit = strXll2.ReverseFind('\\');
strXll2 = strXll2.Left(iSplit + 1) + "SimpOpt.xll";
// Open the bootstrapped XLL
static int xlfRegister = 149;
CXlOper xloResult;
int rc = xloResult.Excel(xlfRegister, 1, &CXlOper(strXll2));
if (rc != 0)
{
XlMessageBox("Failed to open " + strXll2, XlMessageBoxTypeExclamation);
return FALSE;
}
// Other start-up code...
return TRUE;
}
FAQ #0030 has information on calling add-in functions in another XLL.