MS-Excel / General Formatting

Creating a Drop-Down List

Check boxes and toggle buttons are fine when your macro toggles a setting on or off or chooses between two states. However, you'll often need to provide more choices than that.

In a case such as this where you have more than two choices, you can place those items in a drop-down list. To set this up in RibbonX, you begin with the <dropdown> element:

<dropDown id="value"
label="value"
imageMso="value"
size="normal|large"
InsertAfterMso="value"
InsertBeforeMso="value"
onAction="value"
enabled="true|false"
visible="true|false"
screentip="value"
supertip="value"
keytip="value"
showItemImage="true|false"
showItemLabel="true|false"
showImage="true|false"
showLabel="true|false">

Here, the showImage attribute determines whether the image specified by the imageMso attribute is displayed, and the showLabel attribute determines whether the text specified by the label attribute is displayed.

Here's an example:

<dropDown id="lstInsertHyperlinksFor"
	label="Insert Hyperlinks For"
	onAction="Module1.lstInsertHyperlinksFor_OnAction">
</dropDown>

The <dropdown> element creates just an empty drop-down list. To populate the list, you create multiple <item> elements:

<item id="value"
	label="value"
	imageMso="value"
	screentip="value"
	supertip="value" />

In the <dropdown> element, you can use the showItemImage attribute to determine whether the <item> elements' images are displayed. You can also use the showItemLabel attribute to determine whether the <item> elements' labels are displayed.

You insert the <item> elements between the <dropdown> and </dropdown> elements, as in this example:

<dropDown id="lstInsertHyperlinksFor"
	label="Insert Hyperlinks For"
	onAction="Module1.lstInsertHyperlinksFor_OnAction">
    <item id="heading1" label="Heading 1"/>
    <item id="heading2" label="Heading 2"/>
    <item id="heading3" label="Heading 3"/>
</dropDown>

Here's the lstInsertHyperlinksFor_OnAction macro:

Sub lstInsertHyperlinksFor_OnAction(control As IRibbonControl, id As String, index As Integer)
    Select Case id
	Case "heading1"
	    InsertHyperlinks "Heading 1"
	Case "heading2"
	    InsertHyperlinks "Heading 2"
	Case "heading3"
	    InsertHyperlinks "Heading 3"
    End Select
End Sub

Notice that the Sub statement includes not only the usual IRibbonControl object, but also a String variable named id and an Integer variable named index. The id variable returns the value of the id attribute of the <item> object that was clicked in the drop-down list; the index variable returns the index of the clicked <item> object within the list, where the first item in the list has index 0, the second item has index 1, and so on. The procedure uses Select Case to process the id value, and then calls the InsertHyperlinks function with the corresponding style string.

[Previous] [Contents] [Next]