M
Mike Boson
Hi
I'd like to be able to identify if a menu item (any menu item) has been
activated both by click and by accelerator key. I found a message on google
groups that kind of provides a solution but I'm having trouble figuring it
out and I was wondering if anyone might be able to explain how to use it?
The text of the post is below. I understand steps 1-3 but I get lost at
step 4:
How would I call the sub in step 4? Would I just put it in a regular
module? What would be an example of an "Ctrl" argument for the sub in step 4?
Also, I note that the sub is called "MyControl_Click". Would that work even
if the user activated the menu item using an accelerator key, not the mouse?
The post says that code needs to be written to instantiate the class object.
Does that mean a Property Get statement?
Lastly, in step 3 the SaveAs button ID is specified. How would that Set
statement be written if I wanted to get the id number for whatever menu item
was activated?
Many thanks for any help! Here's the original post:
"You can do it by trapping the click event for the control.
1. Add a class module to the VBA project.
2. Declare a variable to trap the events:
Public WithEvents MyControl As Office.CommandBarButton
3. In the module's initialize event, find the control you want to monitor.
Private Sub Class_Initialize()
Set MyControl = Application.CommandBars.FindCoÂntrol(ID:=748)
End Sub
(748 is the ID of SaveAs option on the File menu).
4. Write an event procedure for when the control is clicked:
Private Sub MyControl _Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
MsgBox "FileSave Clicked"
End Sub
The click event is fired before the built-in command is run. Set
CancelDefault = TRUE to prevent the built-in command running.
5. Write some code (eg in AutoExec) to instantiate your class object. You'll
need to re-run this code if you do anything that resets the VBA project,
like editing any code."
(The original post I'm quoting from is
http://groups-beta.google.com/group/microsoft.public.word.vba.general/msg/5c81f19b8c21b4b5?hl=en&)
Thanks again
Mike
I'd like to be able to identify if a menu item (any menu item) has been
activated both by click and by accelerator key. I found a message on google
groups that kind of provides a solution but I'm having trouble figuring it
out and I was wondering if anyone might be able to explain how to use it?
The text of the post is below. I understand steps 1-3 but I get lost at
step 4:
How would I call the sub in step 4? Would I just put it in a regular
module? What would be an example of an "Ctrl" argument for the sub in step 4?
Also, I note that the sub is called "MyControl_Click". Would that work even
if the user activated the menu item using an accelerator key, not the mouse?
The post says that code needs to be written to instantiate the class object.
Does that mean a Property Get statement?
Lastly, in step 3 the SaveAs button ID is specified. How would that Set
statement be written if I wanted to get the id number for whatever menu item
was activated?
Many thanks for any help! Here's the original post:
"You can do it by trapping the click event for the control.
1. Add a class module to the VBA project.
2. Declare a variable to trap the events:
Public WithEvents MyControl As Office.CommandBarButton
3. In the module's initialize event, find the control you want to monitor.
Private Sub Class_Initialize()
Set MyControl = Application.CommandBars.FindCoÂntrol(ID:=748)
End Sub
(748 is the ID of SaveAs option on the File menu).
4. Write an event procedure for when the control is clicked:
Private Sub MyControl _Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
MsgBox "FileSave Clicked"
End Sub
The click event is fired before the built-in command is run. Set
CancelDefault = TRUE to prevent the built-in command running.
5. Write some code (eg in AutoExec) to instantiate your class object. You'll
need to re-run this code if you do anything that resets the VBA project,
like editing any code."
(The original post I'm quoting from is
http://groups-beta.google.com/group/microsoft.public.word.vba.general/msg/5c81f19b8c21b4b5?hl=en&)
Thanks again
Mike