You can call built-in Excel functions from your add-in function. This walkthrough demonstrates how to call Excel functions and how to interpret the results of a built-in function.
Our add-in function will call built-in functions so that it returns the equivalent of:
="Copyright Megacorp Pty, " + ROMAN(YEAR(TODAY))
To create the project using Visual Studio 6
To create the project using Visual Studio .NET or Visual Studio 2005
For more details about creating projects, see Creating an add-in project in the XLL+ User Guide.
// Function: CopyrightNotice
// Purpose: Return a copyright notice
//{{XLP_SRC(CopyrightNotice)
// NOTE - the FunctionWizard will add and remove mapping code here.
// DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN2(CopyrightNotice, "R", "CopyrightNotice", "", "User Defined",
"Return a copyright notice", "", "", 1)
extern "C" __declspec( dllexport )
LPXLOPER CopyrightNotice()
{
CXlOper xloResult;
//}}XLP_SRC
long ldtToday, lYear;
CString strRoman;
// Get the current date
// Get the year of the current date
// Convert year to roman numerals
if (CXlFuncs::Today(ldtToday) == 0
&& CXlFuncs::Year(lYear, ldtToday) == 0
&& CXlFuncs::Roman(strRoman, lYear) == 0)
{
// Construct copyright notice
xloResult.Format("Copyright Megacorp Pty, %s", (LPCSTR)strRoman);
}
else
{
// Return error
xloResult = xlerrNA;
}
return xloResult.Ret();
}
To test the add-in
=CopyrightNotice()