I have a macro that inserts header text into the document. It works perfectly when running it in a .docm file. When I save as to a .dotm the header is not inserted. No errors, just a blank header. The rest of the macro that creates the body works fine.
Any ideas why it fails as a template? Thanks.
Here is the main part of the code:
Code:
For Each objFile In objFolder.Files
'get file path, name and date
strPath = objFile.Path
strDate = Int(objFile.DateLastModified)
StrFName = objFile.Name
'Skip Thumbs.db file if exists
If 0 = InStr(strPath, "Thumbs") Then
'Align Left
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
'Print Header on first loop
If LoopCounter = 0 Then
'Set Variable equal to Header Range
Set HdrRange = ThisDocument.Sections.Item(1).Headers(wdHeaderFooterPrimary).Range
'Text to add to Header
HdrText = "Project Name: " & (ufProjectInfo.tbProjectName.Value)
'Add Text To Word Header
HdrRange.Text = HdrText
'Bold Only First Sentence in Header
'Get length of the project name
ProjectNameLength = ufProjectInfo.tbProjectName.TextLength
Set BoldRange = HdrRange.Words(1) 'Get First Word
'Set selection to the first line of header
BoldRange.SetRange Start:=BoldRange.Start, End:=14 + ProjectNameLength
BoldRange.Font.Bold = True 'Bold Entire Sentence
End If