What are the command(s) to identify an activated VBA button?

R

Richard

Greetings All,

I am trying to find out what is the VBA code that identifies what button has been clicked? In short, is there a way to identify the button's name without first knowing what button has been clicked?

The goal is to write a macro that all buttons are assigned to. The macro must know the name of the button before proceding and therefore the proper routine is then used. Since the routine would be similar for each button, with only minor changes, copying the majority of code seems wasteful for each button.

Thanks.

Richard
 
B

Bob Phillips

Richard,

Assuming you are using Forms buttons, then use

Application.Caller

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Richard said:
Greetings All,

I am trying to find out what is the VBA code that identifies what button
has been clicked? In short, is there a way to identify the button's name
without first knowing what button has been clicked?
The goal is to write a macro that all buttons are assigned to. The macro
must know the name of the button before proceding and therefore the proper
routine is then used. Since the routine would be similar for each button,
with only minor changes, copying the majority of code seems wasteful for
each button.
 
J

jeff

Hi,

Assign a code for each button, and have each one
simply call your master macro, passing in its code-
you can use a number, a letter, or name.

Sub MasterMacro (buttonCode as integer)
if buttoncode = 1 then....
end sub
Private Sub CommandButton1_Click()
MasterMacro 1
End Sub
Private Sub CommandButton2_Click()
MasterMacro 2
End Sub
....

jeff
-----Original Message-----
Greetings All,

I am trying to find out what is the VBA code that
identifies what button has been clicked? In short, is
there a way to identify the button's name without first
knowing what button has been clicked?
The goal is to write a macro that all buttons are
assigned to. The macro must know the name of the button
before proceding and therefore the proper routine is then
used. Since the routine would be similar for each button,
with only minor changes, copying the majority of code
seems wasteful for each button.
 
Top