
Originally Posted by
SamT
I don't see anything wrong with your code.

...

Here is the XML code (had to remove the URL from customUI xmlns as VBA Express would not allow me to post it ...):
<customUI xmlns="schemas.microsoft.com/office/2006/01/customui" xmlns:x="myNameSpace"onLoad="RibbonControl.Onload">
<ribbon startFromScratch="false">
<tabs>
<tab idQ="x:CustomTab"label="Transcription">
<group id="customGroup"label="Templates">
<dropDown id="attachTemplate"label="Attach template"
getItemCount="RibbonControl.GetItemCount"
getItemLabel="RibbonControl.GetItemLabel"
getSelectedItemIndex="RibbonControl.GetSelectedItemIndex"
onAction="RibbonControl.AttachTemplate" >
</dropDown>
</group>
</tab>
</tabs> </ribbon
</customUI>
And now the VBA which is contained within its' own module in normal.dotm:
Option Explicit
Public myRibbon As IRibbonUI
Sub Onload(ribbon As IRibbonUI)
'Creates a ribbon instance for use in this project
Set myRibbon = ribbon
End Sub
'Callback for DropDown GetItemCount
Sub GetItemCount(ByVal control As IRibbonControl, ByRef count)
'Tell the ribbon to show 5 items in the dropdown
count = 5
End Sub
'Callback for DropDown GetItemLabel
Sub GetItemLabel(ByVal control As IRibbonControl, Index As Integer, ByRef label)
'This procedure fires once for each item in the dropdown. Index is _
received as 0, 1, 2, etc. and label is returned.
label = Choose(Index + 1, "--", "Giant Print", "bookx", "magx", "chess")
End Sub
'Callback DropDown GetSelectedIndex
Sub GetSelectedItemIndex(ByVal control As IRibbonControl, ByRef Index)
'This procedure is used to ensure the first item in the dropdown is selected _
when the control is displayed
Select Case control.ID
Case Is = "attachTemplate"
'Index = Index
Case Else
'Do nothing
End Select
End Sub
'Callback for DropDown onAction
Sub AttachTemplate(ByVal control As IRibbonControl, selectedID As String, selectedIndex As Integer)
Dim DummyVar As Integer
Select Case selectedIndex
Case 0 '--
'do nothing
Exit Sub
Case 1 'Giant Print
' taken from sub gwAddGPTemplate
' On Error GoTo errHandler
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "C:\sgmlutil\template\word\bookgp.dot"
End With
MsgBox ("Giant Print template attached!")
Exit Sub
Case 2 'bookx
' On Error GoTo errHandler
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "C:\sgmlutil\template\word\bookx.dot"
End With
MsgBox ("bookx template attached!")
Exit Sub
Case 3 'magx
' On Error GoTo errHandler
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "C:\sgmlutil\template\word\magx.dot"
End With
MsgBox ("magx template attached!")
Exit Sub
Case 4 'chess
' On Error GoTo errHandler
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "C:\sgmlutil\template\word\chess.dot"
End With
MsgBox ("chess template attached!")
Exit Sub
End Select
errHandler: 'from sub gwAddGPTemplate
If Err.Number = 4248 Then
Documents.Add
End If
End Sub