Reference: Q0006
Article Last Modified on 3-Jul-2002
Any add-in function that has been made available to Excel using the IMPLEMENT_XLLFN2() macro is automatically registered when the XLL is opened. Sometimes it is useful to disable this behavior, and only register selected functions.
In the example below, a decision is made at run time (based on the time) to exclude a list of functions from being exposed in Excel.
BOOL CPartialRegApp::InitInstance()
{
// Call the base class
if ( !CXllApp::InitInstance() )
return FALSE;
// Set the name of the library to the default value
m_stName = m_pszDefName;
// Add the statically defined function specifications
AddStaticFns();
// Based on the time, decide whether or not to exclude
// some functions
time_t tm1;
struct tm* tm2;
tm1 = time(0);
tm2 = localtime(&tm1);
BOOL bExclude = (tm2->tm_min % 2 == 0);
// Optionally exclude some functions
const char* apszOptionalFns[] = {
"OptionalFn1",
"OptionalFn2",
0
};
if (bExclude) {
for (int i = 0; apszOptionalFns[i]; i++)
RemoveFn(apszOptionalFns[i]);
}
return TRUE;
}