View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
[email protected] oldyork90@yahoo.com is offline
external usenet poster
 
Posts: 59
Default Command Button Question

On Tuesday, February 18, 2014 8:34:28 PM UTC-6, wrote:
On Tuesday, February 18, 2014 8:14:04 PM UTC-6, wrote:

On Tuesday, February 18, 2014 6:57:09 PM UTC-7, wrote:




On Tuesday, February 18, 2014 6:21:03 PM UTC-6, ron wrote:








I have a Command Button that I created using the Controls Toolbox. The Command Button is placed on a worksheet. What code do I need in the "Private Sub CommandButton1_Click()" macro to capture the name and caption of the Command Button after it has been clicked?..TIA, Ron
















Building a toggle? If it was actX, something like this:








Private Sub CommandButton1_Click()








Dim s As String: s = CommandButton1.Caption








MsgBox s








End Sub








My bad. I should have pointed out that I have 12 command buttons (commandbutton1 through commandbutton12) and 12 modules, so it is not always commandbutton1. Once I click on the command button and I'm in whichever module, how then can I determine the name and caption of the command button that was clicked?..Ron




I take it its a form button. As I understand it actX parts each have an event. The form button has a "macro" assigned to it. In the same (sub) do this:



Dim button_name As String: button_name = Application.Caller



And aside: ... don't ever hide this button


Oops... that won't give you the caption. Hummm.... Ignore that.