Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
I have a word document with the following AutoExec macro, where i'm
attempting to detect the click event of a built in word toolbar button. In this case the numbering icon from the E-Mail menu. Sub AutoExec() Set MyControl = New Class1 End Sub Which also has the following class module named Class1 Public WithEvents MyControl As Office.CommandBarButton Private Sub MyControl_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean) MsgBox "Numbering Clicked" CancelDefault = True End Sub Private Sub Class_Initialize() Set MyControl = Application.CommandBars.FindControl(ID:=11) End Sub Can anyone help me understand what i'm doing wrong? The click event does not trigger. Shawn |
#2
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Hi shawnk,
In your class module you're declaring MyControl as Public which I believe makes it available to your standard code module. In the class it relates to a CommandBarButton but in the code module it relates to the class itself. You could declare it as private in both modules or you could use a different variable in the code module to create an instance of the class. In the code module I think you need to declare whichever variable you are going to use for the class in the Declarations area as if you were to declare it in AutoExec your class would be destroyed as soon as AutoExec finished and the variable went out of scope. You could try something like this: (In the code module) Private MyClickDetector As Class1 Sub AutoExec() Dim MyClickDetector As Class1 Set MyClickDetector = New Class1 End Sub (In the class module) Private WithEvents MyControl As Office.CommandBarButton Private Sub MyControl_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean) MsgBox "Numbering Clicked" CancelDefault = True End Sub Private Sub Class_Initialize() Set MyControl = Application.CommandBars.FindControl(ID:=11) End Sub Cheers. Ed " wrote: I have a word document with the following AutoExec macro, where i'm attempting to detect the click event of a built in word toolbar button. In this case the numbering icon from the E-Mail menu. Sub AutoExec() Set MyControl = New Class1 End Sub Which also has the following class module named Class1 Public WithEvents MyControl As Office.CommandBarButton Private Sub MyControl_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean) MsgBox "Numbering Clicked" CancelDefault = True End Sub Private Sub Class_Initialize() Set MyControl = Application.CommandBars.FindControl(ID:=11) End Sub Can anyone help me understand what i'm doing wrong? The click event does not trigger. Shawn |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
In the edit button the seclet button is gray and i can't click on | Microsoft Word Help | |||
The right click button doesn't work in WORD only. | Microsoft Word Help | |||
add a command button and when i click on the button it will copy | Microsoft Word Help | |||
my send button is not working when i click it | Microsoft Word Help | |||
How do I delete files from the "Work" Built-In Menu button? | Microsoft Word Help |