Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
[email protected] shawnk@phosaic.com is offline
external usenet poster
 
Posts: 2
Default Detect Click Event of Built in Button

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   Report Post  
Posted to microsoft.public.word.docmanagement
Ed Ed is offline
external usenet poster
 
Posts: 217
Default Detect Click Event of Built in Button

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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
In the edit button the seclet button is gray and i can't click on tiffany Microsoft Word Help 0 February 16th 07 04:26 PM
The right click button doesn't work in WORD only. javery Microsoft Word Help 6 June 30th 06 12:55 AM
add a command button and when i click on the button it will copy ronabriones Microsoft Word Help 1 June 22nd 06 07:38 PM
my send button is not working when i click it stacie Microsoft Word Help 1 August 7th 05 04:04 AM
How do I delete files from the "Work" Built-In Menu button? Jedi Word Apprentice Microsoft Word Help 2 February 9th 05 10:13 PM


All times are GMT +1. The time now is 02:58 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"