C
Chip Orange
Hi All,
I'm having a problem with the following code failing to find something which
is in the document. I know it's there because I can type similar code into
the immediate window and have it work (also below).
Fails:
DIM objRange as Word.Range
SET objRange = ActiveDocument.range
WITH objRange.Find
.ClearFormatting
.Text = "Issue"
.Style = ActiveDocument.Styles("Issue Heading")
END WITH
IF objRange.Find.execute() then
....
and it fails. If I type this into the immediate window, using the selection
object like so:
selection.find.ClearFormatting
selection.find.Text = "Issue"
selection.find.Style = ActiveDocument.Styles("Issue Heading")
? selection.find.execute()
and that works!
?
I don't want to use the selection object in my macro for other reasons, and
this is a paired-down example so maybe I left something key out, but I don't
see any essential difference. If I don't use style, but I use attributes
such as bold and underlining, then the first search example works ok, it's
only when searching for text in a specific style that it fails.
Any ideas?
Thanks.
Chip
I'm having a problem with the following code failing to find something which
is in the document. I know it's there because I can type similar code into
the immediate window and have it work (also below).
Fails:
DIM objRange as Word.Range
SET objRange = ActiveDocument.range
WITH objRange.Find
.ClearFormatting
.Text = "Issue"
.Style = ActiveDocument.Styles("Issue Heading")
END WITH
IF objRange.Find.execute() then
....
and it fails. If I type this into the immediate window, using the selection
object like so:
selection.find.ClearFormatting
selection.find.Text = "Issue"
selection.find.Style = ActiveDocument.Styles("Issue Heading")
? selection.find.execute()
and that works!
I don't want to use the selection object in my macro for other reasons, and
this is a paired-down example so maybe I left something key out, but I don't
see any essential difference. If I don't use style, but I use attributes
such as bold and underlining, then the first search example works ok, it's
only when searching for text in a specific style that it fails.
Any ideas?
Thanks.
Chip