Search twice in one loop

J

jvalo

I want to loop through a document doing a search, a second search,
then typing text. Here is a more detailed list

1) search for "[Definition Header]";
2) search for a ": " (colon and space);
3) type a string "^p[Definition Text]" (will replace selected colon
and space)
4) repeat steps 1-3 until the end of document is reached

I can record a macro that does steps 1-3. How can I put that into a
loop to do the entire document?

John
 
H

Helmut Weber

Hi,

you don't need a macro at all.
You could use the find and replace dialog.

Search for:
"([Definition Header]*): "
Replace with:
"\1^13[Definition Text]"
Check:
Use Wildcards
Replace all

Means:
Search for [Definition Header]
followed by anything except a colon followed by a space
followed by a colon followed by a space.
The expression in parentheses is reflected by \1
in the replace textbox.
The rest will be replaced by a paragraph mark ^13
followd by [Definition Text].

But there is more to it than meets the eyes!
Don't try to do this more than once,
if there are sparse colons followed by spaces in your text.

I don't like wildcard searches too much.
IMHO, one needs a special talent for using them.
Some of such talents are around and will speak up, for sure.

However, a macro solution avoiding wildcards,
wouldn't be any simpler, I think, quite the opposite.
The fact that there may still be [Definition Header]
in the text, followd by anything, followed by ": "
would forbid a macro to be used a second time as well.

Some things stay complicated, whatever you do.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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