Microsoft Office Tutorials and References
In Depth Information
Executing a Ribbon Command with a Macro
Here’s another example that displays the Font tab of the Format Cells dialog box:
Sub ShowFontTab()
CommandBars.ExecuteMso “FormatCellsFontDialog”
End Sub
Attempting to execute a command in an incorrect context generates an error. For example, this
statement executes the command that displays the Insert Function dialog box:
CommandBars.ExecuteMso “FunctionWizard”
If you execute this statement when something other than a range is selected (for example, a
chart), you get an error. Here’s a procedure that checks for such an error and displays a friendly
Sub ShowInsertFunction()
On Error Resume Next
CommandBars.ExecuteMso “FunctionWizard”
If Err.Number <> 0 Then
MsgBox “That command is not appropriate.”, vbInformation
End If
End Sub
Search JabSto ::

Custom Search