+ Reply to Thread
Results 1 to 12 of 12

Code to see which button was pressed

  1. #1
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    185

    Code to see which button was pressed

    Hello again all,

    I am trying to write a generic code that will see which button was pressed. I have been playing around with many different ways and I cannot seem to figure one out. I am assuming it is a If, Then statement but my lack of knowledge is hindering me.

    Does anyone know of a simple code that will look to see which button was pressed?

    Any help is appreciated.

    Thank you.

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Code to see which button was pressed

    Please Login or Register  to view this content.
    Gary's Student

  3. #3
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    185

    Re: Code to see which button was pressed

    Thank you for that sample of code.

    But I am trying to have the code figure out which command button that is on the worksheet was pushed and then change the command buttons caption.

    Basically I have a worksheet with multiple command buttons on it. When the user clicks on one of the buttons a user form opens up and the user can input a date into a textbox and then notes into another textbox. Then when the user clicks on the "Save" button that is on the user form, the code looks to see which command button on the worksheet that was pushed that caused the user form to open and save the command buttons caption to the date that was entered into the first textbox.

    I can upload a file if I need to.

    Once again thank you all.

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Code to see which button was pressed

    Here is an extremely simple example..................three buttons on a sheet..............all attached to the same macro.

    The macro determines which button was pressed and changes the "caption" on that button
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    185

    Re: Code to see which button was pressed

    Thank you sir. I can get it to work. I might be posting back because I have to do some modifications.

    One thing I think I was doing wrong though was that I had activex buttons. So, with this code, I assuming that the application caller doesn't work with activex buttons. Is this correct?

    I couldn't get it to at least.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Code to see which button was pressed

    That's correct, it does not.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Code to see which button was pressed

    It is usually not an issue with ActiveX controls (at least for me), because each control has its own macro.

  8. #8
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    185
    Is there anyway that I can get this code to work with an activex button? Would I just put the code into each buttons code?

  9. #9
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    185

    Re: Code to see which button was pressed

    Yeah, when I try to do it with an activex button it gives me the following error.

    HTML Code: 
    Is it a different caller method for an activex button?

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Code to see which button was pressed

    Application.Caller doesn't work for an ActiveX button. There is no direct alternative.
    Last edited by shg; 02-13-2013 at 08:07 PM.

  11. #11
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    185

    Re: Code to see which button was pressed

    Yeah, when I try to do it with an activex button it gives me the following error.

    HTML Code: 
    Is it a different caller method for an activex button?

  12. #12
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Code to see which button was pressed

    I am attaching a workbook that has examples for the "other" kind of button
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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