HelenT
11-07-2016, 05:24 AM
Hi,
I have a start-up template which initialises a custom tab on the ribbon. On this tab is a drop-down menu from which the user can choose to attach one of 4 templates. Irrespective of which template is chosen, the first time a template is chosen from the drop-down menu, the user gets:
"Run-time error 5947. Could not change document template."
However, subsequent attempts to change the template (by choosing a different option on the drop-down menu) are always successful. The error occurs on the first attempt only, irrespective of which template is chosen.
I have included the call back routine which handles the Drop-down menu on the ribbon:
'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
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "C:\sgmlutil\template\word\bookgp.dot"
End With
MsgBox ("Giant Print template attached!")
Exit Sub
Case 2 'bookx
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "C:\sgmlutil\template\word\bookx.dotm"
End With
MsgBox ("bookx template attached!")
Exit Sub
Case 3 'magx
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "C:\sgmlutil\template\word\magx.dotm"
End With
MsgBox ("magx template attached!")
Exit Sub
Case 4 'chess
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "C:\sgmlutil\template\word\chess.dotm"
End With
MsgBox ("chess template attached!")
Exit Sub
End Select
End Sub
Can anyone tell me why the first attempt to change template fails and how I can fix this?
Many thanks, Helen.
I have a start-up template which initialises a custom tab on the ribbon. On this tab is a drop-down menu from which the user can choose to attach one of 4 templates. Irrespective of which template is chosen, the first time a template is chosen from the drop-down menu, the user gets:
"Run-time error 5947. Could not change document template."
However, subsequent attempts to change the template (by choosing a different option on the drop-down menu) are always successful. The error occurs on the first attempt only, irrespective of which template is chosen.
I have included the call back routine which handles the Drop-down menu on the ribbon:
'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
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "C:\sgmlutil\template\word\bookgp.dot"
End With
MsgBox ("Giant Print template attached!")
Exit Sub
Case 2 'bookx
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "C:\sgmlutil\template\word\bookx.dotm"
End With
MsgBox ("bookx template attached!")
Exit Sub
Case 3 'magx
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "C:\sgmlutil\template\word\magx.dotm"
End With
MsgBox ("magx template attached!")
Exit Sub
Case 4 'chess
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "C:\sgmlutil\template\word\chess.dotm"
End With
MsgBox ("chess template attached!")
Exit Sub
End Select
End Sub
Can anyone tell me why the first attempt to change template fails and how I can fix this?
Many thanks, Helen.