Formatted Search in a Macro

D

DR

It is pretty straightforward to do a formatted search (Word 2000), e.g., to
find an instance of a string that is in a particular style or font. When I
put the search in a macro, however, the macro just sanguinely finds the
string without regard to the format. I haven't been able to invest the time
to learn the macro language, so I am limited to using recorded macros. Can
anyone suggest how to solve this? Thanks.
 
L

Larry

DR,

Here are a couple of examples. This finds the text "my text" in the
style called indent:

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("indent")
With Selection.Find
.Text = "my text"
.Replacement.Text = "'"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWildcards = False
End With
Selection.Find.Execute

This finds the text "my text" if it's bolded:

Selection.Find.ClearFormatting
Selection.Find.Font.Bold = True
With Selection.Find
.Text = "my text"
.Replacement.Text = "'"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWildcards = False
End With
Selection.Find.Execute

Larry
 
D

DR

Here is a more useful way to put the question. I have managed to locate the
text of the macros and have thus come out of the middle ages on this.

As an example, this text, created by just keyboarding:

Selection.Find.Style = ActiveDocument.Styles("nameofstyle")
Selection.Find.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = "x"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

is supposed to find the next instance of an 'x' within a paragraph with the
style 'nameofstyle'. Instead it just finds the next x. The style is a
valid style.

Thanks for any help.
 
L

Larry

You need to have

Selection.Find.ClearFormatting

at the beginning.

Further, the line

Selection.Find.ParagraphFormat.Borders.Shadow = False

is not right, but I'm not sure why. If you leave that line out, the
macro will work.

Larry
 
D

DR

Taking out that line did it. Thanks. The line was of course put in by the
app. Big giant have many zits.
 

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