use access vba to insert word document pages numbers in footer

Ron Weston

New member
Local time
Yesterday, 22:30
Joined
Sep 3, 2007
Messages
3
As the title says, I've written code to create a word document using access vba. Everything is done, but I can't get the page numbers in - here is a snippet of the code I'm using:

oDoc.ActiveWindow.ActivePane.View.SeekView = _
wdSeekCurrentPageFooter
With oDoc.ActiveWindow.ActivePane
.Selection.Font.Size = 10
.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Selection.TypeText Text:="Page "
.Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
.Selection.TypeText Text:=" of "
.Selection.Fields.Add Range:=Selection.Range, _
Type:=wdFieldNumPages
.Selection.TypeText Text:=vbTab & vbTab & _
"Printed on " & Date & " at " & Time
End With

When I run it, it stops at the line with wdFieldPage and says:

Object variable of With Block not set

Any help would be appreciated. Thanks.
 

Users who are viewing this thread

Back
Top Bottom