View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Application.Caller

Mark,

Presumably you are trying to have a generic piece of code that determines
what fired it?

For toolbar buttons, you need code like

With Application.CommandBars.ActionControl
'
End With

you can then test any of its properties such as Caption , Id , etc..

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Mark Worthington" wrote in message
om...
I'm wresting with an issue regarding the Caller property. I have used
it to identify what buttons on a worksheet have been clicked, as
follows :

Sub My_Application_Caller()

' Application.Caller responds with the name of the control that was
activated
' ie, the button that was pressed. This enables the assigned button
name to be
' used in the macro as a variable.

MsgBox Application.Caller

Select Case Application.Caller
Case "Button_Application_Caller"
MsgBox "Macro called directly by the " &
Application.Caller & " button!"
Case Else ' Some other method
MsgBox "Macro called via the Procedure, " &
Application.Caller & " button!"
End Select

End Sub

(On the side, even if I use a button to call another procedure which
itself calls the procedure My_Application_Caller, the originating
button call is remembered. Naming the buttons xxx_1, xxx_2 etc enables
the assigned button name to be easily used in a procedure as a
variable).

The problem is trying apply this to Toolbar buttons. It may not be
possible, but I would welcome any assistance. The MsgBox gives "Run
Time Error 13, Type Mismatch" which sounds pretty conclusive (probably
the #REF! error value).

When I used the macro recorder to record copying a toolbar button from
one bar to another, it gave me :

Application.CommandBars("Custom Popup 7255480").Controls(10).Copy
Bar:= _
Application.CommandBars("Custom Popup 7255539")

which may indicate something to someone!

Any help would be much appreciated,

Regards,

Mark