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

Tip: Looking for answers? Try searching our database.

Wildcard search for dashes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason L - 15 Nov 2004 15:16 GMT
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
Klaus Linke - 15 Nov 2004 21:53 GMT
[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
Jason L - 16 Nov 2004 20:54 GMT
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
 

> [Find paras that start with a dash, remove dash, apply list style]
>
[quoted text clipped - 30 lines]
> Regards,
> Klaus
Klaus Linke - 17 Nov 2004 12:32 GMT
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

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.