PDA

View Full Version : Solved: Detect CommandBar button



Bilby
10-03-2006, 03:00 PM
Greetings All,

I have a large number of templates with commandbars etc. When a button is clicked it fires a global macro/procedure and alls okay.
What I would like to do is have a common routine, ie create a new paragraph, highlight the clicked buttons graphic and then styles the paragraph using the buttons tag property.

I can do this by cycling through the commandbars collection and checking for the name of the expected commandbar and then checking the specific buttons tag. But what I want is some easier method of identifying the actual commandbar/button that was pressed. Is there some event that is triggered by a commandbutton?

matthewspatrick
10-03-2006, 07:29 PM
The ActionControl method of the CommandBars collection returns the most recently clicked control.

fumei
10-04-2006, 12:00 AM
The ActionControl method of the CommandBars collection returns the most recently clicked control.Sorry, but that is totally incorrect. It can be used to do so, but ONLY by making the procedure fired by OnAction one that determines this. The OnAction method does NOT return the most recently clicked control.

OnAction returns or sets the name of a Visual Basic procedure that will run when the user clicks or changes the value of a command bar control.

If the procedure used by OnAction say...creates a new paragraph and formats it...then clicking the button will fire THAT procedure. There is absolutely no inherent information gathered on what was the last control clicked.

The example in Help does so......because that is the ONLY thing the buttons do.

OnAction is just a pointer to a procedure. It sets the action to be taken when it is activated. It contains no Property information on which control was activated.

matthewspatrick
10-04-2006, 05:32 AM
fumei,

Please reread my post. I suggested ActionControl, not OnAction.

:)

matthewspatrick
10-04-2006, 05:34 AM
Another option would be to create a class for your CommandBar controls, and use that class to tap into the Click event for the CommandBarButtons. I helped a person do this a while back, but it turned out to be hideously complicated. Perhaps someone more skilled with classes could have simplified it.

fumei
10-04-2006, 07:58 AM
Hi Patrick,

My apologies.....:doh:

Yes, of course you can use the .Tag of ActionControl.....blush...

matthewspatrick
10-04-2006, 08:00 AM
Gerry,

No worries :beerchug:

Bilby
10-04-2006, 10:06 PM
Yo Patrick

:mbounce:ActionControl ActionControl ra ra ra :mbounce:
I love it! Thanks a lot for that little gem.

Bilby

matthewspatrick
10-05-2006, 06:02 AM
Glad that worked out for you, Bilby :thumb