[Solved] Find out which control is calling this macro

Creating a macro - Writing a Script - Using the API

[Solved] Find out which control is calling this macro

Postby VBandOoffice » Fri Jan 25, 2019 1:35 pm

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 5.4, Windows 7, VB.net 2010
VBandOoffice
 
Posts: 25
Joined: Tue Jul 31, 2018 10:11 am

Re: Find out which control is calling this macro

Postby Enesin » Fri Jan 25, 2019 2:13 pm

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.
Attachments
ControlName.ods
(12.75 KiB) Downloaded 18 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!)
Enesin
 
Posts: 12
Joined: Tue Jan 15, 2019 10:02 pm

Re: Find out which control is calling this macro

Postby Lupp » Fri Jan 25, 2019 4:45 pm

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 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2414
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Find out which control is calling this macro

Postby VBandOoffice » Mon Jan 28, 2019 8:59 am

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

Best regards,
VBandOoffice
LibreOffice 5.4, Windows 7, VB.net 2010
VBandOoffice
 
Posts: 25
Joined: Tue Jul 31, 2018 10:11 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests