+ Reply to Thread
Results 1 to 7 of 7

Form - select button & retrieve button name or button's caption

  1. #1
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2019
    Posts
    209

    Form - select button & retrieve button name or button's caption

    Hi,

    I have 5 buttons that i only mapped to 1 Procedure. My issue is I need to know the Button name or caption when it is click.

    Do anyone know how to do that?

    Much appreciated.

    Thank you
    Lex
    Attached Images Attached Images
    Last edited by lexusap; 09-27-2016 at 12:30 AM.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Form - select button & retrieve button name or button's caption

    Hi,

    The simplest method is to use Me.ActiveControl.Caption in your code, as long as the TakeFocusOnClick property of the buttons is set to True- which is the default.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Form - select button & retrieve button name or button's caption

    The easiest option is to share your code so we can take a look and give you a to the point answer.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Registered User
    Join Date
    05-21-2006
    Posts
    5

    Re: Form - select button & retrieve button name or button's caption

    Maybe:

    use the code


    Private Sub UserForm_Initialize()
    '
    CommandButton1.Tag = "CommandButton1"
    CommandButton2.Tag = "CommandButton2"
    CommandButton3.Tag = "CommandButton3"
    CommandButton4.Tag = "CommandButton4"
    CommandButton5.Tag = "CommandButton5"
    '
    End Sub

    Private Sub CommandButton1_Click()
    '
    MsgBox "Caller = " & CommandButton1.Tag
    '
    End Sub

    Private Sub CommandButton2_Click()
    '
    MsgBox "Caller = " & CommandButton2.Tag
    '
    End Sub

    Private Sub CommandButton3_Click()
    '
    MsgBox "Caller = " & CommandButton3.Tag
    '
    End Sub

    Private Sub CommandButton4_Click()
    '
    MsgBox "Caller = " & CommandButton4.Tag
    '
    End Sub

    Private Sub CommandButton5_Click()
    '
    MsgBox "Caller = " & CommandButton5.Tag
    '
    End Sub
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2019
    Posts
    209

    Re: Form - select button & retrieve button name or button's caption

    Hi,

    Thanks for your help, however i still could not figure out what how to fix this.

    Please Login or Register  to view this content.
    So in plain language, when any of the 4 buttons being clicked, it will call BN50_Send_no_Payment_file.
    However depending on which one that has been clicked, i need to configure which file to get & who to send it.



    I have attached sample for your consideration.

    Thanks
    Lex
    Attached Files Attached Files

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Form - select button & retrieve button name or button's caption

    You can change the called routine to
    Please Login or Register  to view this content.
    and the buttons' code to
    Please Login or Register  to view this content.
    However I see no real benefit in having all the buttons call one routine simply so that routine can call other routines for each button. Why do you not rather have each button call its related routine directly?

  7. #7
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2019
    Posts
    209

    Re: Form - select button & retrieve button name or button's caption

    Thanks XLNitWit.

    It works perfectly.

    Regards
    Albert

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] advice activex button vs form button on protected sheet
    By Alina Loredana in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-06-2015, 04:38 AM
  2. Linking a VBA Form Radio Button to a Option Button
    By buwa84 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-05-2014, 01:46 PM
  3. [SOLVED] VBA Changing button.caption with the same Button.Name
    By mcmunoz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-27-2013, 04:58 AM
  4. [SOLVED] Form Button vs ActiveX Button Performance
    By Philb1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-07-2013, 05:21 AM
  5. Hide a picture button placed in all sheets using a option button (form control)
    By lagaranch in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-26-2012, 10:33 AM
  6. [SOLVED] Change Background color of a Form Button or ActiveX Button
    By Aeneren in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-11-2012, 12:19 PM
  7. VBA User Form - Linking Close Button and Cancel Button
    By nivassrii in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-26-2011, 07:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1