I
Ian Jaffray
Hello,
I'm creating documents by opening and converting .htm files into Word using
Word VBA. Styles, and style names, are created automatically during the open
from the CSS properties of the text in the .htm file and the associated CSS
file.
When I use Find in the Word app to find paragraphs with one of the style
names created during the import (for example "transcript-title"), this works
as it normally would. However, when I try the same operation in VBA, it
fails to recognize the style name, and finds nothing.
Of course, I could be making a mistake with the VBA code, but this is pretty
basic, and the same standard code works when trying to Find other styles not
created during the .htm import, so I think that's not the problem. It seems
as if the styles so created during the .htm import are "different" in some
way and are being seen differently from the VBA environment.
In the code below, I have recorded the simple Find a style operation
executed in the Word app, and then tried running the same macro recorded
during that successful Find operation on the same original document. The
Find operation in the app runs successfully and finds all text styled with
"transcript-title", as you'd expect, during the recording of the macro, but
the recorded operation fails when run as a macro.
Has anyone had a similar problem trying to Find styles created during .htm
files importing? Anyone have the Find op work in the app but not from VBA?
Any ideas of what to try?
Stepping through the following macro in VBA, which is just a recording of
the basic Find a style operation, when it hits "Selection.Find.Execute",
nothing is being found; it acts just as if there were no paragraphs styled
with a style of that name.
Thanks very much,
Ian J.
Sub Macro116()
'
' Macro116 Macro
' Macro recorded 06/05/01
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("transcript-title")
Selection.Find.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub
I'm creating documents by opening and converting .htm files into Word using
Word VBA. Styles, and style names, are created automatically during the open
from the CSS properties of the text in the .htm file and the associated CSS
file.
When I use Find in the Word app to find paragraphs with one of the style
names created during the import (for example "transcript-title"), this works
as it normally would. However, when I try the same operation in VBA, it
fails to recognize the style name, and finds nothing.
Of course, I could be making a mistake with the VBA code, but this is pretty
basic, and the same standard code works when trying to Find other styles not
created during the .htm import, so I think that's not the problem. It seems
as if the styles so created during the .htm import are "different" in some
way and are being seen differently from the VBA environment.
In the code below, I have recorded the simple Find a style operation
executed in the Word app, and then tried running the same macro recorded
during that successful Find operation on the same original document. The
Find operation in the app runs successfully and finds all text styled with
"transcript-title", as you'd expect, during the recording of the macro, but
the recorded operation fails when run as a macro.
Has anyone had a similar problem trying to Find styles created during .htm
files importing? Anyone have the Find op work in the app but not from VBA?
Any ideas of what to try?
Stepping through the following macro in VBA, which is just a recording of
the basic Find a style operation, when it hits "Selection.Find.Execute",
nothing is being found; it acts just as if there were no paragraphs styled
with a style of that name.
Thanks very much,
Ian J.
Sub Macro116()
'
' Macro116 Macro
' Macro recorded 06/05/01
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("transcript-title")
Selection.Find.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub