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

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
 
M

ManningFan

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.
 
A

Allen Browne

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
 

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

Top