Hi
along these same lines - do you know if it is possible to use VBA to add to an exisiting header? I do have a template with the
header defined but each time the template is used I want it to automatically addd the project name to the existing header.
I was just going to use a message box on open "what is the name of your project". Then I want the response to be added to the
header of the document.
Thanks in advance for any help.
Jay Freedman wrote:
First things first. You shouldn't be using a macro to create headers.
13-Feb-07
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
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
Previous Posts In This Thread:
Can't get macro to add header or number pages in Word 2007
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.
First things first. You shouldn't be using a macro to create headers.
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
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
EggHeadCafe - Software Developer Portal of Choice
WPF - XAML TabControl MouseEnter TabItem TextBox SelectAll
http://www.eggheadcafe.com/tutorial...9e-a12b3fdf7971/wpf--xaml-tabcontrol-mou.aspx