Wild card Help II

J

Jason L

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
 
H

Helmut Weber

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/
 
J

Jason Logue

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


Helmut Weber said:
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
 

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