Help from Wildcard search gurus.

J

Jason L

Okay, I've programmed a wildcard macro that searches for text that ostensibly
appears in a list format, but it's not formatted according to Word's bullets
and numberings lists. It searches out text that looks like this:
1. text here
2. text here

and replaces it with text formatted in a numbered list. The macro searches
for any number followed by a period, space and then text. It replaces the
number and period with an em dash then reformats the entire text in a
numbered list. This was working fine until the user discovered it was taking
years at the ends of sentences followed by one or two spaces and deleting
some of the numbers. For example, 1957. ends up being 19 or 195 <and the new
sentence begins here>. There is also a macro that searches for unformatted
text that begins with a., b., c. and follows that list structure. This was
working fine until acronyms like s.q. (for square feet) were used.

Here are some samples of my code. I apologize for the length. I realize
there are some redundancies in the code - I am still a newbie at using
wildcard searches in code. Any help would be greatly appreciated:

Replacing unformatted numbered lists:

With Selection.Find
.Text = "[0-9].[!0-9*^13]"
.Replacement.Text = "^+"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With

Selection.Find.Execute Replace:=wdReplaceAll


Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("List Number")

With Selection.Find
.Text = "^+*^13"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("List Number")

With Selection.Find
.Text = "^+*^13"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.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 = "^+"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Replaces unformatted alpha lists with a style called List Alpha:

With Selection.Find
.Text = " [ A-z].[!0-9*^13]"
.Replacement.Text = "^+"
.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].[!A-z*^13]"
.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")

With Selection.Find
.Text = "^+*^13"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.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 = "^+"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

TIA,
Jason
 
K

Klaus Linke

Hi Jason,

It only needs a small change:

Instead of
.Text = "[0-9].[!0-9*^13]"
.Replacement.Text = "^+"
use
.Text = "(^13)([0-9].[!0-9*^13])"
.Replacement.Text = "\1^+"

If you include the paragraph mark that preceeds the numbering, you won't
match numbers in the text.

BTW, there are two Find/Replaces in your macro that never get executed...
you could safely delete them.
Instead of [!0-9*^13] you could use an expression that matches any
whitespace like [^32^s^t]@
The asterisk * in the expression you use is a bit confusing...
"*" isn't treated as a wildcard here, and you probably didn't mean to match
"any character except a number, or asterisk, or paragraph mark"?

Regards,
Klaus
 

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