Common event handler to get the name of ActiveX button clicked in VBA.

前端 未结 1 929
无人及你
无人及你 2021-01-24 06:32

So I was wondering if I can reference the button that was clicked. So I do not have to change the code to much for every button. So here is what I have.

Private          


        
相关标签:
1条回答
  • 2021-01-24 06:57

    The answer in this SO post solves your issue.

    Follow the instructions carefully. It should solve your problem. :)

    EDIT:

    It's pretty easy, actually.

    SCREENSHOTS:

    Set-up of my sheet:

    enter image description here

    Set-up of the VBE, Sheet1's code:

    enter image description here

    NOTE THE HIGHLIGHTED PARTS!

    Set-up of the VBE, Class Module:

    Add a class module by inserting Class Module rather than just Module. The name should exactly be ButtonEvents.

    enter image description here

    Result when CommandButton1 is clicked:

    enter image description here

    ===============

    This is just the basic premise, of course. Instead of showing a message box, you can instead change the code in the class module to have the name stored somewhere or send it to a particular cell, etc.

    Hope this makes it clearer.

    0 讨论(0)
提交回复
热议问题