Handling office CommandBar controls

While working on office applications, there are scenarios when we need to control the functionality of Command Bar controls. With Command Bar I means, menu bars, toolbars, shortcut menus, context menus and submenus on menus. Best way to get the control’s object is to use the FindControl function and get the control using its unique command ID. Command ID list can be obtained from https://support.microsoft.com/kb/213552

 

Outlook.Explorers actExplorer = Application.ActiveExplorer();

CommandBars cmdBars = actExplorer.CommandBars;

 

foreach(CommandBar bar in cmdBars)

{

      if(bar.Name == "Menu Bar")

      {

            //Copy

            control = bar.FindControl(MsoControlType.msoControlButton,2499,null,false,recursive);

            if(control!=null)

            {

            //act on the control, like enable/disable/fire the click event of the control

            }

      }

}