Consulting

Results 1 to 3 of 3

Thread: Solved: Click a command button to get the name of the previous button clicked

  1. #1
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location

    Solved: Click a command button to get the name of the previous button clicked

    In Excel 2003, Using sheet type activex command buttons, I would like to be able to have code in one button that will give me the name (in a msgbox) of the previous button that was clicked .

    Thanks

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,874
    In the sheet's code module:
    [VBA]Dim LastButtonClicked As String' global variable. Put at top of module.
    Private Sub CommandButton1_Click()
    LastButtonClicked = CommandButton1.Name
    'LastButtonClicked = CommandButton1.Caption
    End Sub

    Private Sub CommandButton2_Click()
    LastButtonClicked = CommandButton2.Name
    'LastButtonClicked = CommandButton2.Caption
    End Sub

    Private Sub CommandButton3_Click()
    LastButtonClicked = CommandButton3.Name
    'LastButtonClicked = CommandButton3.Caption
    End Sub

    Private Sub CommandButton4_Click()
    LastButtonClicked = CommandButton4.Name
    'LastButtonClicked = CommandButton4.Caption
    End Sub

    Private Sub CommandButton5_Click() 'This is the new button.
    MsgBox LastButtonClicked
    End Sub
    [/VBA]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    Thank you Sir

    (another one I should have realized on my own)

Posting Permissions

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