+ Reply to Thread
Results 1 to 13 of 13

get caption of the button you click

Hybrid View

  1. #1
    Registered User
    Join Date
    02-20-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    43

    get caption of the button you click

    how to get the caption of the button that is clicked say in a cell

    Also how to extract the number from it

    Please Suggest something

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: get caption of the button you click

    Private Sub CommandButton2_Click()
        Sheet2.Range("A1").Value = CommandButton2.Caption
    End Sub
    Elegant Simplicity............. Not Always

  3. #3
    Registered User
    Join Date
    02-20-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: get caption of the button you click

    Thanks AndyLitch ........sorry for not explaining in detail but the problem is a bit different......

    I want to use a common macro for a number of buttons and hence i don't know the button name i.e. i can't use CommandButton2.Caption.

    Any suggestions

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: get caption of the button you click

    If the buttons are Form buttons assign this macro to each of them.
    Sub GetCaption()
    Dim btn As Button
    
            Set btn = ActiveSheet.Buttons(Application.Caller)
    
            MsgBox "The caption of the button you clicked is .... " & btn.Caption
    
    End Sub
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    02-20-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: get caption of the button you click

    Thanks Norie.....exactly what i needed

    Is there a way such that i can take the number in Caption string....say UPLOAD19 is caption how can i get number 19 from it.......

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: get caption of the button you click

    Does the caption always begin with UPLOAD?

    If it does then you can use Mid.
    intCapNo = Mid(ActiveSheet.Buttons(Application.Caller), 7)

  7. #7
    Registered User
    Join Date
    02-20-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: get caption of the button you click

    PLEASE EXPLAIN....ITS giving Error 438
    object doesn't support this property or method

  8. #8
    Registered User
    Join Date
    02-20-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: get caption of the button you click

    Thanks a lot norie

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: get caption of the button you click

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  10. #10
    Registered User
    Join Date
    02-20-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: get caption of the button you click

    PFA the excel file....attach document_10th.xls

    i want to use this number for my upload and delete button code.....where i can delete the inserted oleobject by taking reference from the number.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: get caption of the button you click

    Sorry, I'm not following.

    Where/when are you getting the error you describe in the previous post?

    Is it actually in the code I posted?

  12. #12
    Registered User
    Join Date
    02-20-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: get caption of the button you click

    click UPLOAD1 and u will get it....

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: get caption of the button you click

    It's a typo, it should be this.
    intCapNo = Mid(ActiveSheet.Buttons(Application.Caller).Caption, 7)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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