commandbar and commandbarbutton events

J

James

I'd like to implement a general handler to capture CommandBarButton events,
in which I could be able to determine which button raised the event.

Is it possible to trap, in Project 2007, the commandbar and commandbarbutton
events.

I've also tried unsuccessfully to use the ActionControl property, but it is
'Nothing'.
 
R

Rod Gill

Hi,

There aren't events for buttons. You need to assign macros to them. In
Project 2007 you can no longer set the onaction property - it's a security
measure..........!

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
J

Jack Dahlgren

I think you can capture them with a com add-in, but not entirely sure. Worst
case you can remove many of them and replace them with your own.

What is it you are trying to do?

-Jack Dahlgren
 
J

James

Its much easier for me to maintain the code base if I can have the buttons
all call the same procedure and then in this procedure determine which button
was clicked and make the call (some of the calls have parameters and
parameters are now not allowed in button calls).

When you say "... I think you can capture them with a com add-in ..."; can
you expand on this?

When you say "Worst case you can remove many of them and replace them with
your own"; what is the 'them'? CommandBars? and if so how does this help the
situation?
 
R

Rod Gill

I think commandButtons have their own event that calls the sub you enter,
you can't call the same procedure. You can have:

sub Button1_Click
Buttonhandler param1
end sub

sub Button2_Click
Buttonhandler param1,param2
end sub

Using this method you get parameters and one handler. However, I don't see
this as being easier to maintain. I prefer keeping them separate as that
facilitates re-using code more easily.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
J

James

Rod - earlier you responded "There aren't events for buttons."
This was in the context of CommandBarButtons; which seems to be true.

Your current response seems more related to a button on a form, which is not
the context of my question.

Then Jack responded when I asked about a COM add-in and I am interested if
you know information along this line.
 
J

Jack Dahlgren

James,

You can add command bars and command buttons using a com add-in. Of course
these buttons can have their own event handlers. This is why I'm asking about
what you are trying to do. What specifically are you trying to achieve?

I believe it is also possible to modify the existing command bars as well so
you could eliminate buttons in the UI that you don't want to see. The only
problem with this is that command keys would still function so you haven't
really eliminated the function. Nor, can you completely trap one of the
functions even if you can detect any of the existing button clicks as there
are typically command keys which do the same thing.

If you want an example of how to add a command bar and button and handler
with a com add-in, let me know. I have an example on my other machine and
could post something about it tomorrow.

-Jack




James said:
Rod - earlier you responded "There aren't events for buttons."
This was in the context of CommandBarButtons; which seems to be true.

Your current response seems more related to a button on a form, which is not
the context of my question.

Then Jack responded when I asked about a COM add-in and I am interested if
you know information along this line.
 
R

Rod Gill

Each button (on a toolbar or form) has its own event. From this event you
can call a common routine. In VBA for Project 2007 you can no longer
programmatically setup the onaction property of commandbuttons, but you can
do this from add-ins.

The best way to create an add-in for Project now is using VSTO 2008. I
recommend using VB as the language so you can benefit from named and
optional parameters.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com



James said:
Rod - earlier you responded "There aren't events for buttons."
This was in the context of CommandBarButtons; which seems to be true.

Your current response seems more related to a button on a form, which is
not
the context of my question.

Then Jack responded when I asked about a COM add-in and I am interested if
you know information along this line.
 
J

James

Yes Jack, I'd very much appreciate your example of how to add a command bar
and button and handler with a com add-in.
 

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