dewgs
06-29-2010, 05:09 AM
Hi all,
I am at a loss and have only recently ventured into using classes within my vba apps. I have a bunch of code that need to run on WindowActivate or doc change events to ensure my custom toolbar remains visible whenever my document has focus (another addin that must be installed hides my toolbar when my doc loses focus).
My question is, can I restrict the code in the eventclassmodule to only apply to my document? As it is in the example below, once the eventclassmodule is intialised, the msg "beta" will appear whenever any document is opened, new or is activated. I would like the code to run only when my document is activated, not other documents.
code from EventClassModuleCMPS class
Public WithEvents App As Word.Application
Private Sub app_WindowActivate(ByVal Doc As Document, ByVal Wn As Window)
MsgBox "beta"
end sub
code from the loadclasscmps module
Public X As New EventClassModuleCMPS
Sub RegisterEventHandler()
Set X.App = Word.Application
End Sub
thanks
EDIT* Also, if anyone else can think of a way to automatically .enabled .visible my toolbar when my document has focus (so to speak) without using ActiveWindow or DocumentChange events, I'm open to suggestions.
I am at a loss and have only recently ventured into using classes within my vba apps. I have a bunch of code that need to run on WindowActivate or doc change events to ensure my custom toolbar remains visible whenever my document has focus (another addin that must be installed hides my toolbar when my doc loses focus).
My question is, can I restrict the code in the eventclassmodule to only apply to my document? As it is in the example below, once the eventclassmodule is intialised, the msg "beta" will appear whenever any document is opened, new or is activated. I would like the code to run only when my document is activated, not other documents.
code from EventClassModuleCMPS class
Public WithEvents App As Word.Application
Private Sub app_WindowActivate(ByVal Doc As Document, ByVal Wn As Window)
MsgBox "beta"
end sub
code from the loadclasscmps module
Public X As New EventClassModuleCMPS
Sub RegisterEventHandler()
Set X.App = Word.Application
End Sub
thanks
EDIT* Also, if anyone else can think of a way to automatically .enabled .visible my toolbar when my document has focus (so to speak) without using ActiveWindow or DocumentChange events, I'm open to suggestions.