Determine which menu item called the current add-in function
static BOOL GetCallingMenu( int& nBar, int& nMenu, int& nItem, int& nSubItem );
The index of the menu bar to which the menu item belongs. Note that the index of the Excel main application menu bar is 10.
The index of the menu within the bar. Note that the index of the first menu is 1.
The index of the item in the menu. Note that the index of the first item is 1. If the function was called from an item on a sub-menu, then nItem will contain the index of the sub-menu in the main menu.
The index of the item in a sub-menu. If the item was not part of a sub-menu then this will contain 0, and should be ignored. Note that the index of the first item is 1.
Returns TRUE if the current add-in function was called from a menu, FALSE if not.
If the current add-in function was called from a menu item, this static function returns TRUE and sets the values of the nBar, nMenu, nItem and nSubItem arguments.
There is a bug in Excel 2007, which means that this method returns inconsistent and incorrect results. Add-ins that must run under Excel 2007 (and optionally other versions of Excel) should instead use CXlMenu::GetCallingMenuItemPosition(). This simpler method works around the Excel 2007 bug and returns correct results under all versions of Excel. Note however that GetCallingMenuItemPosition() has less capability than this method and cannot differentiate between different menus and submenus.