C
Chuck
I've been going nuts trying to figure this one out -- after inserting doc
number and page number fields in footers, then saving the document or
updating all fields in footers, then all content in Primary (not different
first page) footers EXCEPT section 1 primary footers take on the Page Number
style and refuse to accept the Footer style no matter how hard I try to apply
the Footer style. This only happens when I use .PageNumbers.Add (not
..Fields.Add wdPageNumber). I'd like to use .PageNumbers.Add (which inserts
the page number in a text box instead of as an inline field) for ease of
formatting.
We're trying to standardise our footers to include only a document number
(as a field linked to the DMS (document management system)) and a centered
page number. The document number should be formatted in "Footer" style and
the page number in "Page Number" style.
The code below goes through every footer in every section, deletes
everything from each footer , applies the Footer style , inserts the DMS
field flush left and then the page number on a new line above the DMS field.
After running the macro, all the footers appear as they should: the DMS
field in Footer style and the page numbers in Page Number style (page number
fields in centered text boxes in the footer). However, after saving the
document, the primary footer for every section EXCEPT section 1 has Page
Number style applied and the style cannot be changed. This happens
regardless of where the page number text box appears in the footer -- on the
same line as the DMS field or not.
As I mentioned above, if I use ActiveDocument.Fields.Add wdFieldPage in a
different paragraph from the DMS field, each paragraph retains its proper
style (Page Number and Footer respetively).
Anyone have any ideas as to what's going on? Many thanks for any input!
Sub ReformatFooter()
Dim i As Integer
Dim afooter As HeaderFooter
Dim myrange As Range
Dim myCenterTab As Long
With ActiveDocument
For i = 1 To .Sections.Count
With .Sections(i)
For Each afooter In .Footers
With afooter.Range
.Delete
.Style = "Footer"
End With
Next afooter
End With
Next i
For i = 1 To .Sections.Count
With .Sections(i)
For Each afooter In .Footers
ActiveDocument.Fields.Add _
Range:=afooter.Range, _
Type:=wdFieldEmpty, _
Text:="DOCPROPERTY ""DMSLink.Reference"" ", _
PreserveFormatting:=True
With afooter.Range
.Font.Bold = False
.Font.Size = 8
End With
Next afooter
Set myrange = .Footers(wdHeaderFooterPrimary).Range
If .PageSetup.DifferentFirstPageHeaderFooter = False Then
With .Footers(wdHeaderFooterPrimary).PageNumbers
.Add PageNumberAlignment:=wdAlignPageNumberCenter, _
FirstPage:=True
.RestartNumberingAtSection = False
End With
ElseIf .PageSetup.DifferentFirstPageHeaderFooter = True Then
With .Footers(wdHeaderFooterPrimary).PageNumbers
.Add PageNumberAlignment:=wdAlignPageNumberCenter, _
FirstPage:=False
.RestartNumberingAtSection = True
.StartingNumber = 1
End With
End If
End With
Next i
End With
End Sub
number and page number fields in footers, then saving the document or
updating all fields in footers, then all content in Primary (not different
first page) footers EXCEPT section 1 primary footers take on the Page Number
style and refuse to accept the Footer style no matter how hard I try to apply
the Footer style. This only happens when I use .PageNumbers.Add (not
..Fields.Add wdPageNumber). I'd like to use .PageNumbers.Add (which inserts
the page number in a text box instead of as an inline field) for ease of
formatting.
We're trying to standardise our footers to include only a document number
(as a field linked to the DMS (document management system)) and a centered
page number. The document number should be formatted in "Footer" style and
the page number in "Page Number" style.
The code below goes through every footer in every section, deletes
everything from each footer , applies the Footer style , inserts the DMS
field flush left and then the page number on a new line above the DMS field.
After running the macro, all the footers appear as they should: the DMS
field in Footer style and the page numbers in Page Number style (page number
fields in centered text boxes in the footer). However, after saving the
document, the primary footer for every section EXCEPT section 1 has Page
Number style applied and the style cannot be changed. This happens
regardless of where the page number text box appears in the footer -- on the
same line as the DMS field or not.
As I mentioned above, if I use ActiveDocument.Fields.Add wdFieldPage in a
different paragraph from the DMS field, each paragraph retains its proper
style (Page Number and Footer respetively).
Anyone have any ideas as to what's going on? Many thanks for any input!
Sub ReformatFooter()
Dim i As Integer
Dim afooter As HeaderFooter
Dim myrange As Range
Dim myCenterTab As Long
With ActiveDocument
For i = 1 To .Sections.Count
With .Sections(i)
For Each afooter In .Footers
With afooter.Range
.Delete
.Style = "Footer"
End With
Next afooter
End With
Next i
For i = 1 To .Sections.Count
With .Sections(i)
For Each afooter In .Footers
ActiveDocument.Fields.Add _
Range:=afooter.Range, _
Type:=wdFieldEmpty, _
Text:="DOCPROPERTY ""DMSLink.Reference"" ", _
PreserveFormatting:=True
With afooter.Range
.Font.Bold = False
.Font.Size = 8
End With
Next afooter
Set myrange = .Footers(wdHeaderFooterPrimary).Range
If .PageSetup.DifferentFirstPageHeaderFooter = False Then
With .Footers(wdHeaderFooterPrimary).PageNumbers
.Add PageNumberAlignment:=wdAlignPageNumberCenter, _
FirstPage:=True
.RestartNumberingAtSection = False
End With
ElseIf .PageSetup.DifferentFirstPageHeaderFooter = True Then
With .Footers(wdHeaderFooterPrimary).PageNumbers
.Add PageNumberAlignment:=wdAlignPageNumberCenter, _
FirstPage:=False
.RestartNumberingAtSection = True
.StartingNumber = 1
End With
End If
End With
Next i
End With
End Sub