Word Find/Replace Options - wildcards & formatting changes

D

dd

I still use an old word processor because it has wild card find/replace
options that I can't seem to duplicate in Word.

Example:
in this other wp, I can find: ^R^+ replace ^R^+ and set options that will
change the format from, for ex., italic to bold or from no formatting to
italic plus bold. The string in the example consists of anything following a
Return until & incl. a colon. The options allow me to specify the current
format - font/attribute etc. - and what I want the new format to be..

In other words, I want to change the formatting for strings that may contain
a variety of different characters but are bounded by a specific start and a
specific end. (Actually, this wp's find/replace w/ options lets me build
rather complex combinations of wildcards to which formatting changes may be
applied.)

I have been unable to figure out any way to do this in any version of Word.
 
G

Graham Mayor

Wildcards in Word are quite comprehensive -
http://www.gmayor.com/replace_using_wildcards.htm but you cannot format
*part* of a found string in Word directly. It is nevertheless simple enough
to do with a macro e.g.

Dim oRng As Range
With Selection
.HomeKey wdStory
'Look for a paragraph mark followed by text as far as a colon
Do While .Find.Execute("^13*:", MatchWildcards:=True)
'Mark the found text as a range
Set oRng = Selection.Range
With oRng
'Move the start of the range one character,
'to eliminate the paragraph mark
.Start = .Start + 1
'Add Italic formatting to the new range
.Italic = True
'Add Bold formatting
.Bold = True
End With
'And find the next matching string
Loop
End With

However the wildcard character '*' is a rather broad brush, so I would
prefer to tie down the search string rather more tightly than that as it
will find the next paragraph mark and the colon that follows it - regardless
of how many other paragraph marks there may be in between, which may not be
what is required. e.g.
Do While .Find.Execute("^13[a-zA-Z ]{1,}:", MatchWildcards:=True)

The linked page should help with the syntax.


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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