Calling Function With Image Click

  • My worksheet contains multiple images, in which I have programatically been trying to configure a mouse click event for each.

    Here is what I have up to now:

    FName = ThisWorkbook.Path & "\Charts\" & ws.Name & ".GIF"
    Selection.OnAction = "OnMouseClick"

    My problem is, when I raise the mouse click action on the image, it calls a Sub procedure, but doesnt pass any parameters.. I'm trying to figure out how to get a "FUNCTION" to be called instead, so that I can pass a few parameters along with the mouse click.

    I'm open to new methods and suggestions,

  • Hi Jon,

    It depends on WHAT information you think you should be passing.

    You migh be able to make use of the Application.Caller property.
    Assign the same macro to each image

    Sub OnMouseClick()
        Msgbox Application.Caller
    End sub

    It is possible, although I can't get it to work for me :( , to pass arguments.

    You Need to add single quotes round the routine and arguments.

    .Onaction = "'MyTest 2'"

    Sub MyTest(Arg)
    Msgbox Arg
    End Sub


  • thanks

    Your suggestiong for Application.Caller worked.

    Here is my subroutine

    Sub OnMouseClick()
        Dim Pic As Object
        Set Pic = ActiveSheet.Shapes(Application.Caller)
    End Sub

    It actually returns the name of the picture that was clicked... works like a charm

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!