Executing menu and toolbar commands from the InfoPath Object Model

While the InfoPath 2003 SP-1 object model is quite extensive, it doesn’t provide all the functionality that is exposed through the InfoPath menus and toolbars. However, you are not limited by that fact. Using the CommandBars object, you can access any of the functionality available in menus and toolbars.

For example, the InfoPath object model exposes a Print method but not a PrintPreview method. However, that doesn’t mean that you can’t access this functionality. Using the CommandBars object, you can execute the Print Preview functionality available on the Standard toolbar like so:

Application.ActiveWindow.CommandBars(“Standard”).Controls(“Print Preview”).Execute();

The list of available command bars is on the View | Toolbars menu. If you want to access a menu item, use “Menu Bar” for the command bar name. The control name to use is the same name that appears on a menu or in the tooltip when the mouse is hovered over a toolbar button. (Please refer to MSDN (http://msdn.microsoft.com) for more information about the CommandBars object.)