Find text format: problem in Word XP

J

Jonathan Sachs

I have code to find each instance of italic text in a range. It looks
something like this:

Dim r as range, f as font
set r = selection.range
set f = New Font
f.italic = True

With r.Find
.text = ""
.Forward = True
.Wrap = wdFindAsk
.Font = f
.format = True

Do
.Execute Wrap:=wdFindStop
If Not .found Then Exit Do
' (Do some stuff to the italic text)
Loop
End With

This works in Word 2000. In Word XP it doesn't. The ".Execute"
statement never finds anything.

I tried performing the operation manually. That worked. I tried
performing the operation manually and recording a macro so that I
could imitate the recorded code. The recorded code didn't refer to the
font at all -- just as if I hadn't set it!

Can anyone tell me how to perform this operation?

My mail address is jsachs177 at earthlink dot net.
 
C

Chris Worth

I think what your script is currently doing is searching
within the Selection.Range for the text you specify. I
have been using this and it has been working fine.

Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:=FindText,
Forward:=Forward, MatchCase:=MatchCase, _
MatchWholeWord:=WholeWords,
MatchWildcards:=Wildcards, MatchSoundsLike:=SoundsLike,
MatchAllWordForms:=WordForms

Does that work?
 

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