To replace text in a document with headings and feet of page

M

Miguel Angel

Hello,

How can I move for the different sections of heads and foots pages?

I want to realize a massive change of a text and the only way that I have of
doing it is modifying first the wdSeekMainDocument, later a
wdSeekCurrentPageHeader and later a wdSeekCurrentPageFooter, since Word
differentiates it when it does from VBA and does not work like replacing.
But when there are different sections I have to move for them to be able to
realize the modification, and sometimes I have documents without sections,
with two sections, etc.

Anybody help me? I am desperate.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?TWlndWVsIEFuZ2Vs?=,
I want to realize a massive change of a text and the only way that I have of
doing it is modifying first the wdSeekMainDocument, later a
wdSeekCurrentPageHeader and later a wdSeekCurrentPageFooter, since Word
differentiates it when it does from VBA and does not work like replacing.
But when there are different sections I have to move for them to be able to
realize the modification, and sometimes I have documents without sections,
with two sections, etc.
this is NOT the proper way to proceed. you need to loop all the sections in the
document, then access the various header/footer type ranges. Very roughly:

Dim sec as Word.Section
Dim rng as Word.Range

For each sec in Doc.Sections
Set rng = sec.Headers(wdHeaderFooterPrimary).Range
rng.Text = "Your text here"
Set rng = Nothing

Set rng = sec.Headers(wdHeaderFooterFirstPage).Range
rng.Text = "Your text here"
'and so on
Next

Another approach is to loop through a document's StoryRanges collection. Look
this up in Word's VBA Help. There are code samples that show you how to use it.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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