Modify text between certain tags

A

Alex Ivanov

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.
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

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
 
J

just 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?
 
K

Klaus Linke

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
 

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