Tag Text with Placeholders

A

Angie M.

I was reading some other posts and I'm trying to create a solution for a
co-worker.

How can I mark all bolded text in a document? For example I want to put
"mebold" before and after any text that has a bold font applied to it.

I know I should start by looping through the paragraphs collection but
couldn't tell you how to say "type 'mebold' directly before and after all
text that is bold". Can anyone help or steer me to an article? Thank you
 
J

Jean-Guy Marcil

Angie M. said:
I was reading some other posts and I'm trying to create a solution for a
co-worker.

How can I mark all bolded text in a document? For example I want to put
"mebold" before and after any text that has a bold font applied to it.

I know I should start by looping through the paragraphs collection but
couldn't tell you how to say "type 'mebold' directly before and after all
text that is bold". Can anyone help or steer me to an article? Thank you

You do not need a macro for this.
Just use Find/Replace

Open the Replace dialogue (CTRL-H),
Click on the "More" button,
In the "Find what:" field, do not type anything,
But, with the cursor in the "Find what:" field, click on "Format > Font >
Bold",
In the "Replace with:" field, type: <mebold>^&<mebold>,
Click on "Replace All".

I guess yucould record a macro of the above to get an idea of how to do
this if you really want to do this by code.

Also, generally (but not always!), when coding, if you can use Find/Repalce
instead of looping throught he paragraphs collection, do it. It is much
faster.

When in doubt, try both and time the results using a large document.
 
A

Angie M.

Thanks that worked great. Now I'm going to paste that text unformatted into
a new document and re add the bold. I've created a macro that finds
<mebold>, deletes it, does a selection.extend through the next <mebold>,
turns on bold and then deletes the last <mebold>. Should I use a loop for
this part? When I tried to use the Find/Replace to turn bold on it didn't
work, not sure if this is possible. Any thoughts? Thanks again
 
J

Jean-Guy Marcil

Angie M. said:
Thanks that worked great. Now I'm going to paste that text unformatted into
a new document and re add the bold. I've created a macro that finds
<mebold>, deletes it, does a selection.extend through the next <mebold>,
turns on bold and then deletes the last <mebold>. Should I use a loop for
this part? When I tried to use the Find/Replace to turn bold on it didn't
work, not sure if this is possible. Any thoughts? Thanks again

Again, no macro necessary:

In the "Find what:" field, type: \<mebold\>(*)\<mebold\>;
In the "Replace with:" field, type: \1
and select Bold formatting
("More" button > "Format" button > Font > Bold);
Make sure to check "Use wildcards";
Click "Replace All".

Done!

In case you do not know the meaning of wild cards:

\<mebold\>(*)\<mebold\>:
We use the "\" to escape the ">" and "<" characters because in wildcard
searches they nomally mean "End of word" and "Beginning of word"
respectively. Here they are used as actual characters in the text.
The * means any expression. If used alone, it would refer to the whole
document. Here it means whatever is found between the <mebold> tags.
The two ( ) delimit a string of characters.

\1:
Refers to the first string of characters in the "Find what:" area. I this
case we have only one (The stuff between the <mebold> tags).

Consult the Word Help for more examples on wildcard searches and special
characters.
 

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