VBA Code
Documents can sometimes lose their connection to their template
Need to re-attach if invalid or cannot be found.
Application.organizercopy
There is a templates collection for all the templates
Dim objTemplate As Template
For Each objTemplate In Application.Templates
Next objTemplate
You cannot create a new template using the templates collection.
Templates are created by first creating a document and then saving it as a template, using SaveAs
ActiveDocument.SaveAs "newtemplate" wdFormatTemplate
A template is attached to the templates collection whenever you:
● Use the Documents.Open method
● Use the Documents.Add method
● Use the AttachedTemplate property to change the template for a document (i.e. replacing the existing template)
You can use the Application.NormalTemplate property to return a template object that refers to the Normal Template
Dim objTemplate As Template
Set objTemplate = Application.NormalTemplate
Returns the template attached to the active document
Dim objTemplate As Template
Set objTemplate = ActiveDocument.AttachedTemplate
Creates a new document from an existing document
Documents.Add Template:="C:\Temp\Template.doc"
NewTemplate:=True / False
ActiveDocument.AttachedTemplate.Name
ActiveDocument.AttachedTemplate.FullName
Opens a template that is in the Templates collection as a document.
ActiveDocument.AttachedTemplate.OpenAsDocument
Dim objDocument As Document
Set objDocument = ActiveDocument.AttachedTemplate.OpenAsDocument
If objDocument.Content.Text = vbCr Then
'document does not contain any text
Else
'document does contain text
End If
objDocument.Close SaveChanges:=wdSaveOptions.wdDoNotSaveChanges
The following code saves a copy of the Normal.dotm template
Set objDocument = NormalTemplate.OpenAsDocument
objDocument.SaveAs FileName:="C:\Temp\Backup.dot"
objDocument.Close SaveChanges:=wdSaveOptions.wdDoNotSaveChanges
Copying styles from a template
objDocument.CopyStylesFromTemplate
Using the Organiser
Application.OrganizerCopy Source:="C:\Temp\Normal.dotm", _
Destination:="C:\Temp\Document.doc", _
Name:="StyleName_1", _
Object:=wdOrganizerObject.wdOrganizerObjectStyles
VBA - Attached Templates
The AttachedTemplate property returns a Template object that represents the template attached to the specified document.
To set this property, specify either the name of the template or an expression that returns a Template object.
This attaches the template "Letter.dot" to the active document.
ActiveDocument.AttachedTemplate = "C:\Templates\Letter.dot"
ActiveDocument.AttachedTemplate.Type = wdTemplateType.wdNormalTemplate
Dim objTemplate As Template
Set objTemplate = ActiveDocument.AttachedTemplate
Call MsgBox objTemplate.Path & Application.PathSeparator & objTemplate.Name
This example inserts the contents of the Spike (a built-in AutoText entry) at the beginning of document one.
Set myRange = Documents(1).Range(0, 0)
Documents(1).AttachedTemplate.AutoTextEntries("Spike") _
.Insert myRange
VBA - Global Templates
If you need to add a template to the list of Global templates and add-ins on the "Templates and Add-ins" dialog box:
Addins.Add FileName:="C:\Temp\MyGlobalTemplate.dot", Install:=True
Addins.Item("MyGlobalTemplate.dot").Installed = False
VBA - Debugging Templates
Move the (dotm) file to a testing folder
Rename the file so you do not get confused
Open the template
Double click on a template file in the Startup folder, to create a dummy document
Use that as your active document
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrev