Power Query Course in Spanish
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: How to refer to the calling button in a macro

  1. #1
    Guest

    Default

    Hi,

    I hope you can help me. I created a button (from the Forms toolbar) and assigned a macro to it.

    I want to be able to make changes to the button that calls the macro. How do I refer to it? Using "Selection" does not work.

    Thank you!

  2. #2
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi

    This should give you the gist:

    Sub WhoClicked()
    Select Case Application.Caller

    Case "Button 1"
    MsgBox "It was button 1"
    Case "Button 2"
    MsgBox "It was button 2"
    Case "Button 3"
    MsgBox "It was button 3"
    Case "Button 4"
    MsgBox "It was button 4"

    Case Else
    MsgBox "Only buttons please"
    End Select
    End Sub


    Just add 4 buttons and assign them all to this Procedure. If you want to get really flash call your buttons the same name as the Prodecure they should run, then you can use:

    Sub RunWhat()
    Dim strMacroName As String
    strMacroName = Application.Caller
    Run strMacroName
    End Sub



  3. #3
    Guest

    Default

    That's exactly what I was looking for. Thanks!

  4. #4
    New Member
    Join Date
    Apr 2010
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to refer to the calling button in a macro

    Ok, I've looked everywhere and this old post is as relevent to what I am looking for as I can find.

    I have two spreadsheets I am working with; a template and a macro book.

    The template has buttons that run from single macro and uses the case caller above to determine which procedures to do.

    In my macro book, I need to click on a button in the template in order to complete the process I am working on. I basically need something that can call just the "Button 2" case in template macro, or click on Button 2.

    I've tried as many work arounds I can think of, but nothing works. The template cannot be altered and I cannot re-create the Button 2 procedures in my macro book (due to network accessing rights). The only thing I think can be done is calling the case in the template's macro or writing a mouse click procedure (which I am failing at).

    Thanks

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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