You can add your own menus to Excel, by creating CXlMenu objects within your application.
The easiest way to add a menu to your application is to check the "Add a menu" check-box in the XLL+ Application Wizard. This will add code to your application, which creates a menu during OnXllOpenEx() and destroys it during OnXllClose().
A new member object, m_menu is added to the application class, as follows:
class CMenuDemo1App : public CXllApp { public: CMenuDemo1App(); // Names public: static LPCSTR m_pszDefName; // Menu CXlMenu m_menu; ... };
The menu object is initialized and populated in the OnXllOpenEx() method:
BOOL CMenuDemo1App::OnXllOpenEx() { // Set up menu // TODO: Change the menu captions // Write an add-in function to be called when the menu item is clicked // Add other menu items m_menu.SetTexts("&My menu"); m_menu.AddItem("&My menu task", "MyAddinFunction"); m_menu.Create(); // TODO: Allocate any application-level resources return TRUE; }
The menu is destroyed in OnXllClose(), thus:
void CMenuDemo1App::OnXllClose() { // Delete menu m_menu.Destroy(); // TODO: Clean up any application-level resources }
You will need to change the code as follows:
An add-in function that is invoked by a menu should have the following characteristics.
The macro function can interact with the user through dialogs if required, and can interact with Excel through the methods of CXlMacros and other objects.
See Macro functions for more information.
Look at the Simple menus and Advanced menus samples for instructions on using CXlMenu.
Menu texts can be localized, so that they appear in the language of the user. See Internationalization : Commands for more information, the International sample for an example of a localized menu.