Example Macro Invoked by Selecting a Composer from the List

Sub ExampleListMacro()

Dim cbctl As CommandBarControl Find the list box control

Set cbctl = CommandBars("Toolbar Example").

FindControl(Tag:="ComposerList") If Not cbctl Is Nothing Then

MsgBox "You selected " & cbctl.List(cbctl.ListIndex) End If End Sub

In this macro, we use the FindControl method to locate the list box control, via its tag, on the toolbar. Once we have located the list box, we can get the currently selected item (which we simply display for this example). Note that if two or more controls fit the search criteria, FindControl returns the first control that it finds. Also, if no control fits the criteria, FindControl returns Nothing, so we can check this as we have done in our program.

0 0

Post a comment