Put a Dialog Box Launcher on Your Custom Office Ribbon

If you were like me when the Ribbon menu first showed up in Office 2007 I was lost. Many items had been resorted into other categories or simply hidden. Where was the Font or Page Setup dialog boxes? After all these years of working with the Ribbon, I still have to ask the “Tell me what you want to do?” query box for help. However, I did find those dialog boxes and more.

Behind those little diagonal arrows at the lower right of many of the command groups are what Microsoft calls Dialog Box Launchers. They are easy to setup on your own custom Ribbon…

First Things First

The first thing you need is a dialog box which you want to open with the Launcher. Generally with VBA programming you will have a form whose input is central to the group’s “theme”. For example:

The previous image is from an estimating workbook which I coded. There is a Dialog Box Launcher for the Preferences group. What does it open? As you might guess from the Screentip, it is the main Options/Preferences form. This form gives access to all of the workbook’s options, including those reprsented by the checkboxes in the same grouping. How this is done is very simple:

Edit the XML

Using the Custom UI Editor for Microsoft Office, which you can get here, open your document’s ribbon XML The following shows the previous image’s XML layout

                <group id="preferences" label="Preferences">
				<checkBox id="chkMenuMarkUp" label="Mark up Subcontracts" screentip="Mark-up the Subcontracts using the pre-selected Material mark-up percentage." enabled="true" getPressed="GetPressed" onAction="chkBoxControl" />
      			<checkBox id="chkMenuRound" label="Round the Job Total" screentip="Round the Job Total to the nearest even dollar amount (Banker's rounding.)" enabled="true" getPressed="GetPressed" onAction="chkBoxControl" />
				<checkBox id="chkMenuFreeze" label="Freeze Headers" screentip="Freeze the header rows to keep them always visible while you scroll the line items" enabled="true" getPressed="GetPressed" onAction="chkBoxControl" />
				<dialogBoxLauncher>
            			<button id="OptionsLauncher" screentip="Open the Estimator's Options/Preferences form." onAction="mnuShowOptions" />
          			</dialogBoxLauncher>
				</group>

This is a jumble, I agree, but all you really need to understand is the last 4 lines. From the tag <dialogBoxLauncher> to the end tag, </group>. All that needs to be added is the button ID, the Screentip and the name of an onAction Sub procedure to run when the arrow is clicked. The executable code for my mnuShowOptions is simply one line:

Private Sub mnuShowOptions(control As IRibbonControl)
' Callback for btnOptions onAction
    frmOptions.Show
End Sub

After saving your XML and closing the Editor add your code for the onAction parameter and you have a Dialog Box Launcher.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.