View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Similar to "Need to know what is selected"

If you're trying to identify which control's OnAction fired the macro, try
looking at the ActionControl property of Commandbars in VBA help. It returns
a reference to Class CommandBarControl which lists various properties related
to controls. You can query these to know which control fired the macro
something like this:

If Commandbars.ActionControl.Tag = "ThisId" then...

where "ThisId" could be anything descriptive that relates to the control.
You assign the value to the control when it's created (usually). Also, you
could substitute the Tag property for any suitable one in the list. Typically
used ones besides Tag are Parameter and Caption, for example.

If more than one control fires the macro, you can use Select Case to take
the appropriate action based on the value of whatever property or properties
you implement.


If you're looking to identify a procedure that called the macro, you need to
pass a variable to it that identifies the procedure as the "Caller". To use
this method, you would set an argument for the macro something like this:

Sub MyMacro(Optional szCaller as String)

where the line in the calling procedure would be:

MyMacro sSource

where sSource is a string containing the name of the calling procedure. This
is used mostly for error handling, but can be utilized for anything
appropriate. It's declared in that procedure as follows:

Const sSource as String = "MyProcedure()"

Then you can query the argument's value to determine which action to take.
If several procedures call the macro and you need to know which one because
of special requirements for any/each caller, you can do something like this:

Select Case szCaller
Case = "MyProcedure()"
'do this...
Case = "OtherProcedure()"
'do this...
Case Else
'do this...
End Select

I hope this is helpful!
Regards,
GS