Get Name of Macro Initiator

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have many graphical buttons on a sheet with different names/properties but
all initiate the same macro. I need the macro to get the name/properties of
the initiating button.

Is there a "who started me" value I can get?

Thanks,
 
Assume you mean buttons from forms toolbar.
Sub Button_click()
Dim sName as String, btn as Button
sname = Application.Caller
set btn = Activesheet.Buttons(sname)
msgbox btn.Caption
End Sub

If you mean a picture that looks like a button, the approach would be
similar but you couldn't use the buttons collection
 
Hi Space Camel,

Try sometging like:

'=============>>
Public Sub Tester()
MsgBox Application.Caller
'Your code
End Sub
'<<=============
 
Just what I was looking For.

Thanks guys.
'--------------------------

One more thing...

I now need to get the value of the cell that the shape is over.
-----
The shapes were added with this code to put them over the correct cell.
With thiscell
With .Parent.Shapes.AddShape( _
Type:=msoShapeRoundedRectangle, _
Left:=.Left + 2, _
Top:=.Top, _

======================================
 
Hi Space Camel,

Try something like:


'=============>>
Public Sub Tester()
Dim Rng As Range
Dim SHP As Shape

Set SHP = ActiveSheet.Shapes(Application.Caller)

Set Rng = SHP.TopLeftCell
MsgBox Rng.Address(0, 0, External:=True)

End Sub
'<<=============
 
You're putting the shape over ThisCell (with a minor adjustment to the right
(.left + 2)).

I'm gonna bet that you're still over ThisCell.

So you could use
ThisCell.value
to get the value.
 
That did it!

Works great.

Thanks again.
-----------------------------------
 
Consider naming your shapes with the address of the cell they're supposed to
be over.
Then you can just use:

Msgbox Activesheet.Range(Application.Caller).Value

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top