Insert data into headers, textboxes,...

P

Paul Malfait

Hello,
I'm looking for a way to insert text into headers and textboxes with a
macro.
I've read a lot about replacing text everywhere in a document as decribed in
http://word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm , but that
doesn't solve my problem.
I want to put variable text into headers etc. depending on certain codes I
put there before, formatted as ##001, ##002, ##003 etc.
So I want to search for a '##'-string, then select the next 3 characters,
and depending on the value of these chars replace the 5-char string (##001)
by a text that is present in memory.

When I do this in the main text I can use Selection.Find to search for the
## and the Selection.Moveright to select the next 3 characters, so I have
no problem there to delete the selected text and insert new text.

But when I have to loop through the StoryRange to scan all headers,
textboxes, etc. I don't know how to select text in there. It is as if the
cursor stays in the main text, and if I try to select text in the header
with Selection.Moveright (after having found the ##-code), the selection is
extended in the main text instead.

I hope anyone understands my problem and can help me.

Tnx

Paul Malfait
 
C

Cindy M -WordMVP-

Hi Paul,

Mmmm, yes. "Selection" in the headers/footers doesn't work very well. you
should stick to using RANGE.
I'm looking for a way to insert text into headers and textboxes with a
macro.
I've read a lot about replacing text everywhere in a document as decribed in
http://word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm , but that
doesn't solve my problem.
I want to put variable text into headers etc. depending on certain codes I
put there before, formatted as ##001, ##002, ##003 etc.
So I want to search for a '##'-string, then select the next 3 characters,
and depending on the value of these chars replace the 5-char string (##001)
by a text that is present in memory.

When I do this in the main text I can use Selection.Find to search for the
## and the Selection.Moveright to select the next 3 characters, so I have
no problem there to delete the selected text and insert new text.

But when I have to loop through the StoryRange to scan all headers,
textboxes, etc. I don't know how to select text in there. It is as if the
cursor stays in the main text, and if I try to select text in the header
with Selection.Moveright (after having found the ##-code), the selection is
extended in the main text instead.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
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