Discussion Locked

Font Change in Word Macro

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I created a macro that inserts 'Author, Page #, Date' in the footer, changing the font for 'author' and 'date' from size 12 font to size 8. This works fine in the initial document; however, when it is run as a macro, the font does not always hold but affects random parts of the information. Any suggestions?

1 reply

by dklippert

Sub FooterItems()
'
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
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If

'I think this is the trick, put the formatting first

Selection.Font.Size = 8

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"AUTHOR ", PreserveFormatting:=True
Selection.TypeText Text:=vbTab

'Restore Font-Size

Selection.Font.Size = 12

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PAGE ", PreserveFormatting:=True
Selection.TypeText Text:=vbTab

Selection.Font.Size = 8

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DATE ", PreserveFormatting:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

This discussion is closed to new replies.