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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
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.
 

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

Back
Top