J
Jon Borel
Hello,
In my custom Word 2003 template, I have the following application event
procedure to check the style at the current insertion point (or selection):
Public WithEvents AppThatLooksInsideThisEventHandler As Word.Applicatio
----------------------------------------------------------------------------------
Private Sub AppName_WindowSelectionChange(ByVal Sel As Selection)
If Selection.Type = wdSelectionNormal Or _
Selection.Type = wdSelectionIP Then
If Selection.Style = ActiveDocument.Styles("Bold Word") Then
Do this
Else
Do This
End If
End If
End Sub
It works great UNTIL I open a new "Normal" document while I have a document
based on this custom template open. Then, the event handler run-time errors
with "The requested member of the collection does not exist" and debug takes
me to the line:
If Selection.Style = ActiveDocument.Styles("Bold Word")
I'm pretty sure this is because the new "Normal" document doesn't include
the "Bold Word" style. (I'm surprised the Else condition doesn't handle
this.) So, I need a way to tell VBA to only run the event handler for
documents based on the (current) custom template, not for (external) "Normal"
documents.
Thanks in advance for your consideration,
Jon
In my custom Word 2003 template, I have the following application event
procedure to check the style at the current insertion point (or selection):
Public WithEvents AppThatLooksInsideThisEventHandler As Word.Applicatio
----------------------------------------------------------------------------------
Private Sub AppName_WindowSelectionChange(ByVal Sel As Selection)
If Selection.Type = wdSelectionNormal Or _
Selection.Type = wdSelectionIP Then
If Selection.Style = ActiveDocument.Styles("Bold Word") Then
Do this
Else
Do This
End If
End If
End Sub
It works great UNTIL I open a new "Normal" document while I have a document
based on this custom template open. Then, the event handler run-time errors
with "The requested member of the collection does not exist" and debug takes
me to the line:
If Selection.Style = ActiveDocument.Styles("Bold Word")
I'm pretty sure this is because the new "Normal" document doesn't include
the "Bold Word" style. (I'm surprised the Else condition doesn't handle
this.) So, I need a way to tell VBA to only run the event handler for
documents based on the (current) custom template, not for (external) "Normal"
documents.
Thanks in advance for your consideration,
Jon