Page 1 of 1

[Solved] Find out which control is calling this macro

PostPosted: Fri Jan 25, 2019 1:35 pm
by VBandOoffice
Hi all,
I have several Textfield-Controls in a spreadsheet. The user may change one of them. If the control lost focus a macro is called. This macro should change the text to all other Textfield-Controls.
One possibility is to have one macro for each Textfield-Contol.

Is there a better way? - Use one macro for all of the Textfield-Controls?

Have a nice weekend,
VBandOoffice

Re: Find out which control is calling this macro

PostPosted: Fri Jan 25, 2019 2:13 pm
by Enesin
I've just been dealing with the sort of thing your thread title asks. Other than that, I don't know what is best for you to do.

Code: Select all   Expand viewCollapse view
Sub YourMacro(oEvent as object)
Dim CtrlName as String
CtrlName = oEvent.Source.Model.Name
Print "Calling control is named: """ & CtrlName & """"
'...stuff I don't know how to write...
end sub


This gives your macro the name of the control that calls it in a string named "CtrlName".
Is that what you wanted?

I knocked up a demo sheet because sleep is the enemy.

Re: Find out which control is calling this macro

PostPosted: Fri Jan 25, 2019 4:45 pm
by Lupp
Please note that the .Name property not is forced uique here. It's simply the name given using the control editor (first line). Many controls can get the same name this way. If you want to identify controls by name you never should edit the name.

Re: Find out which control is calling this macro

PostPosted: Mon Jan 28, 2019 8:59 am
by VBandOoffice
Hi Enesin,
Super! - That's what I'm looking for - Thank you very much!

Best regards,
VBandOoffice