Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Mar 2008
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I identify a command button name (2003)

    Is there a way to identify a command button's name after I click on it? For example, I have 42 command buttons, using default excel names of CommandButton1 - 42. After I click on any one of the command buttons for the purpose of executing a macro. Can I have the macro identify the command buttons name without having to specificly say Commandbutton1.name. For what I'm trying to do, I want to be able to identify the number in the name of the command button and assign the number to a variable for later use in the macro. Is this possible??

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How can I identify a command button name (2003)

    If you're using command buttons from the Forms toolbar, you can use

    Application.Caller

    to retrieve the name of the button.

  3. #3
    Star Lounger
    Join Date
    Mar 2008
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can I identify a command button name (2003)

    Hans, Thanks for the reply. I'm using the command buttons that you can assign to the forms you can create under the visual basic window. I assume this is what your referring to. Any way you could provide and example. I'm having trouble getting the Application.Caller to work. Thanks!!

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How can I identify a command button name (2003)

    Sorry, I erroneously assumed that you meant command buttons on a worksheet. For command buttons on a userform, you can use

    Me.ActiveControl.Name

    if the code is in the userform's own module. If you call it from elsewhere, you can use something like

    UserForm1.ActiveControl.Name

    where UserForm1 is the name of the userform.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •