Hi all!

How to modify (i.e. toggle bold) all the strings in document which are
between certain tags? Strings are like: ##THIS_IS_A_STRING##

Spaces between tags "##" are not allowed. So, all the occurences in the
Word document should be modified, how could this be done?

Re: Modify text between certain tags by Alex

Alex
Sat Jan 24 17:09:49 CST 2004

You can use Word's Find object for this, but it is going to be slow.
I would recommend replacing your tags with bookmarks, then you will get
almost instant access to them.

Alex.

"just me" <no.spam@to.me> wrote in message
news:pan.2004.01.25.01.20.31.717310@to.me...
> Hi all!
>
> How to modify (i.e. toggle bold) all the strings in document which are
> between certain tags? Strings are like: ##THIS_IS_A_STRING##
>
> Spaces between tags "##" are not allowed. So, all the occurences in the
> Word document should be modified, how could this be done?
>



Re: Modify text between certain tags by Doug

Doug
Sat Jan 24 17:49:29 CST 2004

Use

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Execute FindText:="_", ReplaceWith:=" ", Replace:=wdReplaceAll,
MatchWildcards:=False
Do While .Execute(FindText:="(##)([A-z 0-9]{1,})(##)",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Range.Bold = True
Selection.Range.Text = Mid(Selection.Range.Text, 3,
Len(Selection.Range.Text) - 4)
Loop
End With


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
"just me" <no.spam@to.me> wrote in message
news:pan.2004.01.25.01.20.31.717310@to.me...
> Hi all!
>
> How to modify (i.e. toggle bold) all the strings in document which are
> between certain tags? Strings are like: ##THIS_IS_A_STRING##
>
> Spaces between tags "##" are not allowed. So, all the occurences in the
> Word document should be modified, how could this be done?
>



Re: Modify text between certain tags by Klaus

Klaus
Sun Jan 25 13:24:30 CST 2004

> Do While .Execute(FindText:="(##)([A-z 0-9]{1,})(##)",
> MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True


If spaces aren't allowed, you can make the macro safer by using
[!^32]@
(any text, but no spaces) instead of
[A-z 0-9]{1,}

It would probably be faster if you simply replace with "\2" ... then you can
"replace all", and the "Do While" isn't necessary.

"Find/Replace" is usually the fastest solution for this kind of problem. You
might apply a character style instead of "bold", then future changes (say
"red" instead of "bold") are achieved nearly instantly by changing the style
definition.

Greetings,
Klaus