bug report re page nums?

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
 
C

Chad DeMeyer

Chuck,

I think part of the problem is that Page Number style is a character style,
so reapply Footer style, which is a paragraph style, will not automatically
remove Page Number style. To remove Page Number style, you can apply
DefaultParagraph style, which is like the Normal of character styles.

Regards,
Chad
 
C

Chad DeMeyer

Chuck,

Whenever use add a page number this way instead of using a PAGE field, Word
automatically inserts it with Page Number style applied. So, if need to use
the PageNumbers collection instead of the Fields collection, you will need
to use the kludge.

Regards,
Chad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top