# Excel VBA Command Button



## curtswanson (Jun 22, 2000)

How do I reference the command button that called a particular "on click" subroutine from within the subroutine? The name of the button is part of the subroutine title but I don't know how to reference it.

Sub CommandButton1_Click()
Dim ReferringButton as Shape
Set ReferringButton = ????????
debug.print range(ReferringButton.BottomRightCell.Address).Value
End Sub

Right now I have to hard code either the button name or the associated cell in each button's subroutine. Any help greatly appreciated.


----------



## Zack Barresse (Jul 25, 2004)

Hi there,

Depending on your controls (there are many), check out the Application.Caller method. 

HTH


----------



## curtswanson (Jun 22, 2000)

Thanks. My controls were created using the ActiveX control toolbar and the application.caller doesn't work with that. I think I will change the buttons to the type created with the forms toolbar.


----------



## Zack Barresse (Jul 25, 2004)

Yes, you'll need a Forms control if you want to use that. If you don't, your routines will be in the sheet module anyway. What you can do is create a public variable (preferably in a standard module) and call a common routine (probably also in a standard module) and pass the variable - which we'll assume you set the controls name to. A little more overhead work, but the same (more or less) results.


----------

