Word VBA Macros – Templates (Make New)
Current Template
This Word VBA macro will display the current template:
Sub DisplayCurrentTemplate()
'displays full path of template active document
MsgBox ActiveDocument.AttachedTemplate.FullName, , "Template location"
End Sub
Make New Template
This Word VBA macro will make a new template:
Sub MakeNewTemplate()
'creates a new doc and saves as a template
Dim strName As String
Dim strPath As String
Dim oDoc As Document
strPath = Options.DefaultFilePath(wdUserTemplatesPath) & Application.PathSeparator 'find where templates are stored at user's computer
strName = "Sample automateexcel.com template.dotm"
Set oDoc = Documents.Add 'create a new doc and asign it to oDoc variable
'write some text in the new doc reffering to it using oDoc variable
oDoc.Range.InsertBefore "Sample template"
oDoc.Range.InsertParagraphAfter
oDoc.Range.InsertAfter "Visit https://autovbax.com/"
oDoc.SaveAs FileName:=strPath & strName, FileFormat:=wdFormatXMLTemplateMacroEnabled, AddToRecentFiles:=False
oDoc.Close wdDoNotSaveChanges 'close doc
End Sub