I am trying to record a macro that does a variety of things, and can't get it
to work.

I want the macro, in addition to other things, to create a header; and I
want the header to include a line that says Page x of y.

When the macro gets to the point that it is to create the header, I get an
error message referring to "Run time error 5941" and telling me "the
requested member of the collection does not exist"

I also can't even find a page numbering option that allows me to have a Page
x of y format.

Re: Can't get macro to add header or number pages in Word 2007 by Jay

Jay
Tue Feb 13 21:03:53 CST 2007

First things first. You shouldn't be using a macro to create headers.
You should create a template with everything already in the header,
and documents based on that template will inherit the header without
any programming at all.

To see how to set up Building Blocks for proper Page X of Y headers
and footers, see
http://groups.google.com/group/microsoft.public.word.formatting.longdocs/msg/ab71df395f60bad2?hl=en&.

Finally, if you _must_ use a macro for some reason, you can't record
it; you have to program it from the start. Here's a demo of the kind
of work you have to do:

Sub MakeXofYHeader()
' this makes a right-aligned header
' containing only "Page X of Y"
' in the first section of the document

Dim oRg As Range
Set oRg = ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterPrimary).Range
With oRg
.Text = vbTab & vbTab & "Page "
.Collapse wdCollapseEnd
.Fields.Add Range:=oRg, Type:=wdFieldPage
End With
Set oRg = oRg.Paragraphs(1).Range
With oRg
.Collapse wdCollapseEnd
.Text = " of "
.Collapse wdCollapseEnd
.Fields.Add Range:=oRg, Type:=wdFieldNumPages
End With
Set oRg = oRg.Paragraphs(1).Range
oRg.Fields.Update
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Tue, 13 Feb 2007 17:09:00 -0800, Kurt
<Kurt@discussions.microsoft.com> wrote:

>I am trying to record a macro that does a variety of things, and can't get it
>to work.
>
>I want the macro, in addition to other things, to create a header; and I
>want the header to include a line that says Page x of y.
>
>When the macro gets to the point that it is to create the header, I get an
>error message referring to "Run time error 5941" and telling me "the
>requested member of the collection does not exist"
>
>I also can't even find a page numbering option that allows me to have a Page
>x of y format.