Summer,
I am not really sure which example of mine that you are referencing but
since I am learning bits and pieces everyday things often change ;-). I am
by no means an expert and there is likely a better way. However, this is
how I would go about creating multiple dropdowns in a group.
First I have learned that it seems to be much easier to use call backs as
much as possible for defining the Ribbon. Here is the XML that would create
a custom Tab, with a custom Group, holding four dropdowns. You could add as
many as you want.
getItemImage="GetItemImage" getSelectedItemIndex="GetSelectedItemIndex"
getItemScreentip="GetItemScreenTip" getItemSupertip="GetItemSuperTip"
onAction="MyDDMacro">
onAction="MyDDMacro">
onAction="MyDDMacro">
onAction="MyDDMacro">
The first dropdown is a little souped up with extra features while the other
three contain the bare bones to make them functional.
You will notiice that they all use the same callbacks.
Now in the VBA you simply use the same call backs and the Select Case method
to deal with each control:
Option Explicit
Public myRibbon As IRibbonUI
Sub Onload(ribbon As IRibbonUI)
Set myRibbon = ribbon
End Sub
Sub MyDDMacro(ByVal control As IRibbonControl, selectedId As String,
selectedIndex As Integer)
Select Case control.id
Case "DD1"
Select Case selectedIndex
Case Is = 1
'Report some data
MsgBox "Font name: " & Selection.Font.Name & ". Font size: " &
Selection.Font.Size
Case Is = 2
'Call a builtin Word command
Application.Run "ChangeCase"
Case Is = 3
'Call another procedure in this project
SampleModule.RandomizeCharactersInWordsFirstAndLastExclusive
End Select
'I invalidate the control so that "Select item" reappears after the
action is taken. You wouldn't do this if you want the selected item to
remain displayed.
myRibbon.InvalidateControl control.id
Case "DD2"
'Add another Select Case statement here similiar to the one shown above.
Case "DD3"
Case "DD4"
Case Else
'Do Nothing
End Select
End Sub
Sub GetSelectedItemIndex(ByVal control As IRibbonControl, ByRef Index)
Select Case control.id
Case "DD1"
Index = 0
Case "DD2"
Index = 0
Case "DD3"
Index = 0
Case "DD4"
Index = 0
Case Else
'Do nothing
End Select
End Sub
Sub GetLabel(ByVal control As IRibbonControl, ByRef label)
Select Case control.id
Case "DD1"
label = "Sample Dropdown List 1"
Case "DD2"
label = "Sample Dropdown List 2"
Case "DD3"
label = "Sample Dropdown List 3"
Case "DD4"
label = "Sample Dropdown List 4"
Case "CustomTab"
label = "Sample Tab"
Case "Grp1"
label = "Sample Group"
Case Else
'Do Nothing
End Select
End Sub
Sub GetItemLabel(ByVal control As IRibbonControl, Index As Integer, ByRef
label)
Select Case control.id
Case "DD1"
Select Case Index
Case Is = 0
label = "Select Item"
Case Is = 1
label = "Item 1"
Case Is = 2
label = "Item 2"
Case Is = 3
label = "Item 3"
End Select
Case "DD2"
Select Case Index
Case Is = 0
label = "Select Item"
Case Is = 1
label = "Item 1"
End Select
Case "DD3"
Select Case Index
Case Is = 0
label = "Select Item"
Case Is = 1
label = "Item 1"
Case Is = 2
label = "Item 2"
End Select
Case "DD4"
Select Case Index
Case Is = 0
label = "Select Item"
Case Is = 1
label = "Item 1"
Case Is = 2
label = "Item 2"
Case Is = 3
label = "Item 3"
Case Is = 4
label = "Item 4"
Case Is = 5
label = "Item 5"
End Select
Case Else
'"Do Nothing"
End Select
End Sub
Sub GetItemImage(ByVal control As IRibbonControl, Index As Integer, ByRef
image)
Select Case control.id
Case "DD1"
Select Case Index
Case Is = 0
image = "OutlineCollapse"
Case Is = 1
image = "FileStartWorkflow"
Case Is = 2
image = "FileStartWorkflow"
Case Is = 3
image = "FileStartWorkflow"
End Select
Case Else
'Do Nothing
End Select
End Sub
Sub GetItemID(ByVal control As IRibbonControl, Index As Integer, ByRef id)
Select Case control.id
Case "DD1"
Select Case Index
Case Is = 0
id = "DD1"
Case Is = 1
id = "DD2"
Case Is = 2
id = "DD3"
Case Is = 3
id = "DD4"
End Select
Case Else
'Do Nothing
End Select
End Sub
Sub GetItemCount(ByVal control As IRibbonControl, ByRef count)
Select Case control.id
Case "DD1"
count = 4
Case "DD2"
count = 2
Case "DD3"
count = 3
Case "DD4"
count = 5
Case Else
'Do Nothing
End Select
End Sub
Sub GetImage(ByVal control As IRibbonControl, ByRef image)
Select Case control.id
Case "DD1"
image = "ContentControlDropDownList"
Case Else
'Do Nothing
End Select
End Sub
Sub GetItemScreenTip(ByVal control As IRibbonControl, Index As Integer,
ByRef screentip)
Select Case control.id
Case "DD1"
Select Case Index
Case Is = 0
screentip = "This is the default displayed item."
Case Is = 1
screentip = "Select this second item to do ..."
Case Is = 2
screentip = "Select this thrid item to do ..."
Case Is = 3
screentip = "Select this fourth item to do ..."
End Select
Case Else
'Do Nothing
End Select
End Sub
Sub GetItemSuperTip(ByVal control As IRibbonControl, Index As Integer, ByRef
supertip)
Select Case control.id
Case "DD1"
Select Case Index
Case Is = 0
supertip = "This is the Supertip text: Blah, blah, blah."
Case Is = 1
supertip = "This is the Supertip text: Blah, blah, blah."
Case Is = 2
supertip = "This is the Supertip text: Blah, blah, blah."
Case Is = 3
supertip = "This is the Supertip text: Blah, blah, blah."
End Select
Case Else
'Do Nothing
End Select
End Sub
Hope this gets you on course.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Greg Maxey - Word MVP
My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Summer"
news:OJ8EYd5eIHA.2000@TK2MSFTNGP03.phx.gbl...
> Help please - throwing myself in at deep end and dog paddling to create a
> working Custom Tab with multiple dropdowns plus buttons!
>
>
>
> I'm cobbling together a custom Tab but wanting multiple dropdowns (not
> just one) and ideas on VBA of how to simplify all the dropdowns in the one
> Ribbon Module. All my dropdowns have loaded in the TAB as they should but
> I'm just not sure how to approach the VBA Ribbon Module to cope with
> multiple Dropdown IDs and macros?
>
>
>
> Based on Greg Maxey's dropdown sample - does anyone have any ideas how to
> best simplify the module RibbonControl (Greg?) to incorporate ALL
> groupids: DD DD1 DD2 in the VBA project? I'm going to have about 15
> dropdowns all up - my working macro Custom Tab."
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> > idMso="StylesModifyStyle" />
>
>
> getItemLabel="GetDDLabels">
>
>
>
>
> getItemLabel="GetDDLabels">
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> > idMso="StylesModifyStyle" />
>
>
> getItemLabel="GetDDLabels">
>
>
>
>
> getItemLabel="GetDDLabels">
>
>
>
>
>
> Et cetera....
>
>
>
> Code Module which needs to be expanded on to include ALL the IDs for
> dropdowns and Cases for the macros - Am I being too simplistic expecting
> the macros to be sequential Macro1 to Macro50 and expecting to modify the
> DD Id?:
>
>
>
> Option Explicit
>
> Sub GetDDIndex(ByVal control As IRibbonControl, selectedID As String,
> _
> selectedIndex As Integer)
> Select Case selectedIndex
> Case 0
> Macros.Macro1
> Case 1
> Macros.Macro2
> Case 2
> Macros.Macro3
> Case 3
> Macros.Macro4
> Case 4
> Macros.Macro5
>
> Case 5
> Macros.Macro6
>
> Case 6
> Macros.Macro7
>
> End Select
> End Sub
>
> Sub GetDDCount(ByVal control As IRibbonControl, ByRef count)
> count = 7
> End Sub
>
> Sub GetDDLabels(ByVal control As IRibbonControl, _
> index As Integer, ByRef label)
> Dim i As Long
> For i = 0 To index
> label = Choose(i + 1, "Clear Text", _
> "Macro Clear FR", _
> "Macro 3", _
> "Macro 4", _
> "Macro 5", _
> "Macro 6", _
> "Macro 7")
> Next i
> End Sub
>
> Sub Doc_Clean(ByVal control As IRibbonControl)
> Macros.Doc_Clean
> End Sub
>
>
>
>
>
>