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 / December 2004

Tip: Looking for answers? Try searching our database.

Wild card Help II

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason L - 19 Nov 2004 18:13 GMT
Hey, I have another crazy wildcard search.  I have a search that finds any
unformatted list beginning with a letter, then a period and then any text
until a paragraph mark.  The macro then replaces the list with a formatted
list style called ListAlpha.  These lists often range in length from a-g,
maybe longer.  The macro was working fine, but lately the user has other
entries in the document that the wildcard search is finding, even though it
shouldn't.  For example, it finds any middle name initial followed by a
period.

Here is the macro thus far:

With Selection.Find
       .Text = " [ A-z].[^32^s^t]@"
       .Replacement.Text = "1/^+"
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchAllWordForms = False
       .MatchSoundsLike = False
       .MatchWildcards = True
   End With
   Selection.Find.Execute Replace:=wdReplaceAll

   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
       .Text = "[ A-z].[^32^s^t]@"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = True
       .MatchCase = False
       .MatchWholeWord = False
       .MatchAllWordForms = False
       .MatchSoundsLike = False
       .MatchWildcards = True
   End With
   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   Selection.Find.Replacement.Style = ActiveDocument.Styles("ListAlpha")

TIA,
Jason
Helmut Weber - 19 Nov 2004 21:40 GMT
Hi Jason,
keep on!
> With Selection.Find
>        .Text = " [ A-z].[^32^s^t]@"
>        .Replacement.Text = "1/^+"
hm..., doesn't make any sense to me.
The 1/ should probably be \1, but would require an expression
inclosed in parenthesis (). Apart from other complications,
and apart from the fact, that wildcardsearch needs quite a bit
of a trial and error approach, (and some things simply don't work),
here is what i've figured out:
Search for a paragraph starting with some letters followed by "."
(^13)([A-z]{1,}.)
Paragraph would be expression \1 later.
Instead of {1,} one should be able to use @, but doesn't work here.
Include whitespace after ".":
(^13)([A-z]{1;}.)([^32^s^t]{1,})
Again, ^w for whitespace doesn't work, therefore [^32^s^t]{1,}.
As the characters and the whitespace can be grouped together,
we arrive at:
(^13)([A-z]{1,}.[^32^s^t]{1,})
Now we got to search until the paragraphs end.
That would be one ore more characters, that are not chr(13).
([!^13]{1,})
All together it could look like:
"(^13)([A-z]{1,}.[^32^s^t]{1,})([!^13]{1,})"
So we got 3 expressions,
expression1 is the preceding paragraph mark, which we leave untouched,
expression2 is
the letters following, plus the period plus the whitespace
expression3 is the remainder.
Follows
.Replacement.Text = "\1\3"
which means "cut off expression \2".
Apply the formatting to the result.
Here is my test macro, which could be improved by using
range instead of selection, and in some more ways, I guess.
Sub Test661()
ResetSearch
With Selection
  .ExtendMode = False
  .HomeKey unit:=wdStory
  With .Find
     .Text = "(^13)([A-z]{1;}.[^32^s^t]{1;})([!^13]{1;})"
     .Replacement.Text = "\1\3"
     .MatchWildcards = True
     ' define formatting
     .Execute Replace:=wdReplaceOne ' for testing
   End With
End With
ResetSearch
End Sub
Public Sub ResetSearch()
With Selection.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = ""
  .Replacement.Text = ""
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Execute
End With
End Sub
HTH
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Jason Logue - 03 Dec 2004 23:43 GMT
Helmut,

Hi, I am sorry this is so delayed, but I got caught up in some other
work before I could test the macro you supplied me.  When I run the
macro, it gives me an error that says, the Find What contains a
Pattern Match that is not a valid Expression.  Do you know what this
means or why I am getting this error?

Here is the code clipped from the larger macro:

ResetSearch
With Selection
  .ExtendMode = False
  .HomeKey unit:=wdStory
 
With Selection
   .ExtendMode = False
  .HomeKey unit:=wdStory
  With .Find
     .Text = "(^13)([A-z]{1;}.[^32^s^t]{1;})([!^13]{1;})"
     .Replacement.Text = "\1\3"
     .MatchWildcards = True
     ' define formatting
     .Execute Replace:=wdReplaceAll
   End With
End With

TIA,
Jason L

> Hi Jason,
> keep on!
[quoted text clipped - 71 lines]
> Word XP, Win 98
> http://word.mvps.org/

Rate this thread:






 
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.