Re: Selection using Wildcards



Edward,

In that case don't include the .Text line at all. You are simply looking
for a style.

Sub Scratchmacro()
Dim oRng As Word.Range
Set oRng = Selection.Range 'or ActiveDocument.Range
With oRng.Find
.MatchWildcards = True
.Wrap = wdFindContinue
.Style = ActiveDocument.Styles("Numeral Font")
.Replacement.Text = "PREFIX^&SUFFIX"
.Execute Replace:=wdReplaceAll
End With
End Sub


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Edward Thrashcort wrote:
Thanks Greg I'll no go and examine the Help file to understand the
meaning of "[0-9]{1,}" particularly "{1,}" part

However in my example, I used numerals just to make the problem
clearer. In reality the font that I'm searching-for could contain
ANYTHING, maybe even pictures, tables and stuff.

Eddie

*From:* "Greg Maxey" <gmaxey@xxxxxxxxx>
*Date:* 23 Mar 2007 12:23:49 -0700

Try:
Sub Scratchmacro()
Dim oRng As Word.Range
Set oRng = Selection.Range 'or ActiveDocument.Range
With oRng.Find
.Text = "[0-9]{1,}"
.MatchWildcards = True
.Wrap = wdFindContinue
.Style = ActiveDocument.Styles("Numeral Font")
.Replacement.Text = "PREFIX^&SUFFIX"
.Execute Replace:=wdReplaceAll
End With
End Sub

On Mar 23, 2:51 pm, IdontWantS...@xxxxxxxxxx (Edward Thrashcort)
wrote:
I'm trying to select all the phrases in a document that are written
in a particular character style and replace them with a PREFIX
followed by a SUFFIX. So let's assume that I have specified a
character font for numerals and assigned it only to the numbers in
the following range...

abc 123 xyz 999 pqr

it would be replaced with

abc PREFIX123456SUFFIX wxy PREFIX999SUFFIX pqr

With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.Forward = True
.Wrap = wdFindContinue

.Style = ActiveDocument.Styles("Numeral Font")
.Text = "(*)"
.Replacement.Text = "PREFIX\1SUFFIX"

'For testing I'll replace both separately
'The code should be .Execute Replace:=wdReplaceAll

.Execute Replace:=wdReplaceOne
.Execute Replace:=wdReplaceOne
End With

Unfortunately this code only selects the FIRST character then the
SECOND character - not the first phrase and the second phrase

I've also tried
.Text = "(*@)"
.Text = "(?@)"
I've tried
.Format = False
.Format = True (not quite sure what this means anyway!)

but nothing works!

Am I trying to do something that "wildcards" is not capable of
performing?

Eddie


.



Relevant Pages