Home > database >  How do I know the name of an image I clicked on that has a macro assigned to it
How do I know the name of an image I clicked on that has a macro assigned to it

Time:03-03

I have an image with the assigned name 'boo', represented as a shape in my excel document. I have a macro assigned to 'boo'. When I click the boo image to activate the macro, I'd like to be able to know the .name of the image I clicked.

selection.name did not work, as clicking an image that has a macro is not the same as selecting an image with .select.

In essence, if I click on an image to activate the assigned macro, how can I find out the name of the image?

CodePudding user response:

Using Application.Caller With Shapes

  • Add this code to your procedure. The worksheet needs to be active (selected) to get the information, it won't work when run from VBE but with the If statement you will avoid the error.
Sub TestCaller()
    
    Dim iName As String
    If TypeName(Application.Caller) = "String" Then
        iName = Application.Caller
        MsgBox "The procedure was called from '" & iName & "'.", vbInformation
    End If
    
End Sub
  • Related