XLL+ Class Library (7.0)

Supporting earlier Excel versions

Code generated by the AppWizard

In the XLL+ AppWizard, if you select ribbon support as well as menus and/or toolbars, the code generated will automatically suppress the menus and toolbars in Excel 2007 and above, but will show the menus and toolbars in Excel 2003 and below. And of course in Excel 2003 and below, no ribbon will be displayed.

Routing actions through macros

An alternative method of routing commands from the ribbon is to use the callback attribute OnActionButtonRunTag, which will call the macro specified in the control's tag attribute. e.g.:

CopyXML
<button id="MyPushButton" image="MyImage" size="large" label="My command" 
        onAction="OnActionButtonRunTag" tag="Macro1()" />

This callback routes the command directly to Excel (via the Excel object model method Application.ExecuteExcel4Macro). If your XLL contains an add-in function named Macro1 which is a macro command, then the macro will be invoked whenever the user clicks the the button.

This approach allows you to write UI code that works in all Excel versions. For example, the code below creates a menu that is equivalent to the ribbon button example above:

CopyC++
BOOL CMyAddin::OnXllOpenEx()
{
    if (!SupportsRibbon())
    {
        // Set up menu
        m_menu.SetTexts(_T("&My menu"));
        m_menu.AddItem(_T("&My command"), _T("Macro1"));
        m_menu.Create();
    }

    return TRUE;
}

So in Excel 2007 or above, a group is added to a tab on the ribbon, and the group will contain a button labelled "My command". When the button is pushed by the user, the macro function Macro1 is run. In Excel 2003 or below, a menu "My Menu" is created, and a menu item "My command" is added to the menu. When the menu item is clicked by the user, the macro function Macro1 is run. A similar approach can be used with toolbar buttons.

For more information about the "RunTag" action callbacks, see the reference topic Ribbon RunTag actions.

Next: Menus >>

See Also

Ribbon Reference