Using Events with AddIns

G

Greg Maxey

I have a document template with the following code:

A standard project module:

Option Explicit

Private myDynamicMenu As myClass1

Sub AutoOpen()
Set myDynamicMenu = New myClass1
End Sub

A Class Module (myClass1):

Option Explicit
Private WithEvents mWordApp As Word.Application

Private Sub Class_Initialize()
Set mWordApp = Word.Application
End Sub

Private Sub mWordApp_WindowSelectionChange(ByVal oSel As Selection)
MsgBox "Test"
End Sub

When I change the selection the Msgbox fires.

When I try to use this template as an AddIn, the Msgbox doesn't fire.

I am thinking that this is because the class isn't initialized when the
AddIn is loaded. How do I modify this code so that if this code was in an
AddIn and the AddIn is loaded then I would see the message box every time
the selection is changed?

Thanks.
 

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