Header on certain pages of document programmatically.

X

XmlAdoNewbie

Hi All

I have a question regarding word headers and footers. I have a
document that is dynamically created and I need a header on certain
pages of the document i.e) if the document is 20 pages long I will
need the header on pages 15-17. I have 2 sections in my document and I
am pretty sure the pages I want headers on are a separate section from
the rest of the document however when I execute the code the header
appears on all the pages. Any idea how to do this?? Here is the code I
use.

Set myrange = ActiveDocument.Range(Start:=endPageNo, End:=pageNo)
ActiveDocument.Sections.Add Range:=myrange
h = myrange.Information(wdActiveEndSectionNumber)

For Each oSection In ActiveDocument.Sections
Debug.Print oSection.Index
If oSection.Index = h Then
oSection.PageSetup.DifferentFirstPageHeaderFooter = True
oSection.Headers(wdHeaderFooterPrimary).Range.Text = "Test"
End If
Next

Regards,
Erin
 
J

Jezebel

You'll need to be more than 'pretty sure' - you need to be certain. Word
organises headers and footers according to the document's sections. You'll
also need to set or clear the LinkToPrevious property for the sections (this
is equivalent to the 'Same as previous' button on the Headers and Footers
toolbar). You want that set to false for the first section that has headers,
true for any following sections that also have headers, and false for any
further sections that do not have headers.

Otherwise your headers are deemed to be linked; setting the content in any
section updates the headers in all sections.
 
X

XmlAdoNewbie

Jezebel,
Thanks so much for your response, You are right "pretty sure" just
didn't cut it, the sections aren't correct and that's why the header
isn't working as i want it to.
Regards,
Erin
 

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