Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS word: referring to headers of different sections

Status
Not open for further replies.

davikokar

Technical User
May 13, 2004
523
IT
hallo,

I have a different header for every new section of my word document.

These headers are different but every header contains one shape element.

I am trying to modify the shape element in each header, but I always modify only the header of the section 1.

The code I use to iterate through the different headers is this one:

Code:
doc.Sections(section).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Shapes(1).IncrementTop(23.25)
where "doc" is the ActiveDocument and "section" is the iterator variable from 1 to n. No matter what "section" is, I always modyfing the shape 1 in section 1.

Someone knows?

thanks
 
Is it possible that all your sections have the same name? Try referring to the sections by number: doc.Sections(n)... where n=1 to doc.Sections.Count

_________________
Bob Rashkin
 
that's actually what I am doing: "section" is an integer
 
Please post your code.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
This is a bug.

Try this instead:

[green]
Code:
[blue]Doc.Sections(Section).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.ShapeRange(1).IncrementTop (23.25)[/blue]
[/green]

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
You are not giving full code, but..using objects...
Code:
Dim oHF As HeaderFooter
Dim oSection As Section

For Each oSection In ActiveDocument.Sections
   Set oHF = oSection.Headers(wdHeaderFooterPrimary)
   oHF.Range.ShapeRange(1).IncrementTop (23.25)
Next
That would only change Primary. If you need ALL the headers changed in each Section...
Code:
Dim oHF As HeaderFooter
Dim oSection As Section
Dim j As Long

For Each oSection In ActiveDocument.Sections
   For j = 1 to 3
      Set oHF = oSection.Headers(j)
      oHF.Range.ShapeRange(1).IncrementTop (23.25)
   Next
Next
which actions all the headers (Primary, DifferentFirst, and OddEven) in each Section.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top