Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2007

Tip: Looking for answers? Try searching our database.

Selection using Wildcards

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Edward Thrashcort - 23 Mar 2007 19:51 GMT
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
Greg Maxey - 23 Mar 2007 20:23 GMT
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...@nospam.net (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
[quoted text clipped - 45 lines]
>
> Eddie
Edward Thrashcort - 24 Mar 2007 11:38 GMT
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@gmail.com>
> *Date:* 23 Mar 2007 12:23:49 -0700
[quoted text clipped - 65 lines]
> >
> > Eddie
Graham Mayor - 24 Mar 2007 13:03 GMT
{1,} means at least 1
http://www.gmayor.com/replace_using_wildcards.htm

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Thanks Greg I'll no go and examine the Help file to understand the
> meaning of "[0-9]{1,}" particularly "{1,}" part
[quoted text clipped - 75 lines]
>>>
>>> Eddie
Greg Maxey - 24 Mar 2007 14:17 GMT
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

Signature

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

> Thanks Greg I'll no go and examine the Help file to understand the
> meaning of "[0-9]{1,}" particularly "{1,}" part
[quoted text clipped - 75 lines]
>>>
>>> Eddie
Edward Thrashcort - 24 Mar 2007 22:23 GMT
Yes that worked perfectly thanks

Eddie
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.