Wildcard search for dashes

J

Jason L

Hi, I am trying to program a wildcard search for paragraphs that begin with a
dash. Here is an example of what it looks like:

- text text.
- text text.
- text text.

None of this uses the normal bulleted list templates, but I need to replace
them with a bulleted list. The problem now is having the wild card search
discriminate between dashes in social security numbers and other locations.

Here is the code I have so. In this code the en dash replaces the
dash/hyphen. Right now this code is not working the way I would like.

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = "^13-*^13"
.Replacement.Text = "\1^+"
'.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("ListAlpha")

Selection.HomeKey Unit:=wdStory


'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

'

With Selection.Find
.Text = "^32[0-9]."
.Replacement.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


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



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

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

[Find paras that start with a dash, remove dash, apply list style]

Hi Jason,

You can do it with three simple replacements (...two if you use wildcards):

1.
Find what: ^p-^w
Replace with: ^p#list#

#list# is just some arbitrary tag to mark up the list paragraphs.
^p-^w matches a para mark, a hyphen, and any whitespace like spaces or tabs
that follow it.

2.
Find what: #list#
Replace with: ((list style))

3.
Find what: #list#
Replace with: ((nothing... leave empty))


With wildcards, you can combine 2. and 3.:
Use Wildcards,
Find what: #list#(?)
Replace with: \1 ((plus list style))

\1 inserts the stuff that is in (brackets). In this case, that's the ?
wildcard, matching any character that followed the #list# tag.
This applies the list style ("List Alpha" in your case), and at the same
time removes the #list# tag.

Regards,
Klaus
 
J

Jason L

Klaus,

Thanks so much. Here is the code I have thus far. Right now it's actually
replacing the areas with the following {{ListAlpha}}, instead of the actual
style. I'm pretty sure I did something wrong. Would you mind looking the
small bit of code and helping out. I'd appreciate it. Thanks.

With Selection.Find
.Text = "^p-^w"
.Replacement.Text = "^p#list#"
'.Replacement.Text = "^+"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With

Selection.Find.Execute Replace:=wdReplaceAll



Selection.HomeKey Unit:=wdStory

With Selection.Find
.Text = "#list#"
.Replacement.Text = "{{ListAlpha}}"
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With

Selection.Find.Execute Replace:=wdReplaceAll

''This code then clears any formatting and begins the search.
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

'

Selection.HomeKey Unit:=wdStory

With Selection.Find
.Text = "#list#"
.Replacement.Text = "{{ }}"

.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With

Selection.Find.Execute Replace:=wdReplaceAll
 
K

Klaus Linke

Hi Jason,
2.
Find what: #list#
Replace with: ((list style))

That meant:
Type "#list#" in "Find what:"
Leave "Replace with empty (or use "^&" = Find what text), go to "More >
Format > Styles" and select your "List Alpha" style.

Word then goes to each occurrence of "#list#", and applies your style.

Then, in the 3rd replacement, you delete the tag "#list#" by replacing it
with nothing.

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