[Solved] Find out which control is calling this macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
VBandOoffice
Posts: 33
Joined: Tue Jul 31, 2018 10:11 am

[Solved] Find out which control is calling this macro

Post 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
Last edited by VBandOoffice on Mon Jan 28, 2019 9:00 am, edited 1 time in total.
LibreOffice 7.5, Windows 10, VB.net 2019, C#
Enesin
Posts: 12
Joined: Tue Jan 15, 2019 10:02 pm

Re: Find out which control is calling this macro

Post 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

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.
Attachments
ControlName.ods
(12.75 KiB) Downloaded 161 times
Last edited by Enesin on Fri Jan 25, 2019 10:32 pm, edited 2 times in total.
Apache Open Office 4.1.3 on Windows 7 (64bit)
There are no stupid questions. I mean, except for mine...
(&%#@ code! Don't do what I TELL you to do, do what I WANT!)
User avatar
Lupp
Volunteer
Posts: 3553
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Find out which control is calling this macro

Post 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.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
VBandOoffice
Posts: 33
Joined: Tue Jul 31, 2018 10:11 am

Re: Find out which control is calling this macro

Post by VBandOoffice »

Hi Enesin,
Super! - That's what I'm looking for - Thank you very much!

Best regards,
VBandOoffice
LibreOffice 7.5, Windows 10, VB.net 2019, C#
Post Reply