I have been working on this for 2 days and am really frustrated. Need help.
I am trying to insert the page number in the footer of a newly created document. I want it to look like Page x of y. I can write text to the header and footer already. I just can not insert the field for the Page number and Numer of Pages in the footer. I can write "Page" but the numbering won't go. Can anyone please help? Here is where I am now:
Set Doc = word.documents.Add
With Doc '.documents.Sections(1)
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Bold = True
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Paragraphs.Alignment = wdAlignParagraphCenter
.Sections(1).Headers(wdHeaderFooterPrimary).Range.text = (strHeader)
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Paragraphs.Alignment = wdAlignParagraphCenter
.Sections(1).Footers(wdHeaderFooterPrimary).Range.text = .Sections(1).Footers _
(wdHeaderFooterPrimary).Range.Fields.Add(Range:=Selection.Range, Type:=wdFieldAutoNum, _
text:="Page", PreserveFormatting:=True) & " of " & .Sections(1).Footers(wdHeaderFooterPrimary) _
.Range.Fields.Add(Range:=Selection.Range, Type:=wdFieldNumPages, text:="Pages ", PreserveFormatting:=True)
End With
I have also tried this:
Dim oRng As Range
With Doc.Fields
.Add Range:=Selection.Range, Type:=wdFieldPage
.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertBefore text:="Page "
.Collapse Direction:=wdCollapseEnd
.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertAfter (" of ")
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Paragraphs(1).Alignment = wdAlignParagraphRight
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Collapse Direction:=wdCollapseEnd
.Add Range:=Selection.Range, Type:=wdFieldNumPages
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Start = .Sections(1).Footers(wdHeaderFooterPrimary).Range.Paragraphs(1).Range.End
.Sections(1).Footers(wdHeaderFooterPrimary).Range.End = .Sections(1).Footers(wdHeaderFooterPrimary).Range.Paragraphs(1).Range.End
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Paragraphs(1).Alignment = 1 'wdAlignParagraphCenter
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Collapse Direction:=wdCollapseEnd
End With
The second code will not get me past the .InsertBefore as I get an error message "Object does not support this Property or Method"
Any help would be great. I have looked everywhere.
Thanks.
Just for reference I am usign XP and Access 2003.
