Got a new computer from work. Office 365 build 2102. The macro I used to make a header with document name and page number does no longer work, tried to make a new one, it looks fine and I save the macro, but when I execute on another file, the doc name is missing. I guess there is a problem in the first couple of lines.
My new not functioning macro (showing only — {page number} :
Sub TitelInvoegen()
‘
‘ TitelInvoegen Macro
‘
‘
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.TypeText Text:=” — ”
Application.Templates( _
“C:\Users\leijen000\AppData\Roaming\Microsoft\Document Building Blocks\1043\16\Built-In Building Blocks.dotx” _
).BuildingBlockEntries(“Alleen nummer”).Insert Where:=Selection.Range, _
RichText:=True
Selection.TypeText Text:=” ”
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
My old macro was shorter:
Sub TitelInvoegen()
‘
‘ TitelInvoegen Macro
‘
With Selection.Sections(1).Headers(wdHeaderFooterPrimary).Range
.Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty,
Text:=”FILENAME”, PreserveFormatting:=False
.InsertAfter ” — ”
.Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty,
Text:=”PAGE”, PreserveFormatting:=False
End With
End Sub