Solved: Change Attachedtemplate with VBA
Hi,
I have some templates on a network share and i want to change the location of te attachted Template. So al the documents based on the old template must be attachted to the new template.
I thought it was simple to place VBA code in the old template and the trigger the Document_Open event and then change the attachtedtemplate like this (this is a example):
Private Sub Document_Open()
If LCase(Application.Dialogs(wdDialogToolsTemplates).Template) = LCase("c:\temp\template.dot") Then
ActiveDocument.AttachedTemplate = "c:\temp2\template.dot"
End If
end sub
This option works great when the template name is not the same. When the template has the same name (in this case template.dot) then the attachtedtemplate is not changed..
I tried serveral different locations but nothing works. It works when the template has a different name, but i don't want that.
Is there a solution for this problem.
Thanks.
Jolanda.
Template attachment problem...
Hi Jolanda,:hi:
you can attach the template by using the below code.
Private Sub Document_Open()
If LCase(Application.Dialogs(wdDialogToolsTemplates).Template) = LCase("c:\temp\template.dot") Then
ActiveDocument.AttachedTemplate= application.NormalTemplate.Path & "Normal.dot"
ActiveDocument.AttachedTemplate = "c:\temp2\template.dot"
End If
end sub
or
Private Sub Document_Open()
If LCase(Application.Dialogs(wdDialogToolsTemplates).Template) = LCase("c:\temp\template.dot") Then
ActiveDocument.AttachedTemplate= ""
ActiveDocument.AttachedTemplate = "c:\temp2\template.dot"
End If
end sub
Thanks,
S. Senthil Kumar.