Can you use the name of a sub routine within itself in vba

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I have 60 command buttons on a touch screen form. Is there a way to refer
to the name of the sub routine. E.g. I have a command button - cmd1, with
the code behind the form cmd1_click - AddItem Me.cmd1.Caption. Is it
possible to have something along the lines of Left(SUBNAME,4).Caption?

Thanks
 
Well, the subname is actually the name of the control, isn't it? So
you could pass the name of the control to a variable and possibly use
something like:
"" & ControlName & "".Caption

I've never tried it so I don't know if that's a valid reference or not.
 
Unfortunately, VBA does not expose the name of the procedure that is
exectuing.

Unless it was called programmatically, you may be able to derive if from:
Form.ActiveControl.Name
 
Back
Top