Ask Your Question

How to get push button label text from within macro

asked 2019-02-06 02:43:56 +0100

josh2008 gravatar image


i am trying to find away to appen to a shell command extra parameters that will be held in push button labels.

for example

I could have loads of push buttons with labels

X 222 X 5432 Y 5443 Y 55353 G 56554

I would need the macro to get the append the label text to the shell command

is this possible?

edit retag flag offensive close merge delete


Macros are an advanced technique. I suggest you read the Libreoffice manuals related to macros first.

EasyTrieve gravatar imageEasyTrieve ( 2019-02-06 08:45:30 +0100 )edit

@: "... extra parameters that will be held in push button labels..."
Did you also consider to create hyperlinks instead of buttons for the purpose? A hyperlink can also be used to call a subroutine provided by the user.

Sorry. Just tested it and it didn't work the way I tried (and thought to remember).

Lupp gravatar imageLupp ( 2019-02-06 12:35:59 +0100 )edit

2 Answers

Sort by » oldest newest most voted

answered 2019-02-06 11:44:48 +0100

Lupp gravatar image

updated 2019-02-06 23:20:20 +0100

In addition to what @EasyTrieve said:
When writing a macro for handling a FormControl event you need to provide a formal paramtere for the event. When called due to an action on the button this parameter gets an object assigned that contains all the needed information. Its indirect property .Source.Model gives access to the control (a PushButton in your case) having raised the event. There you also find the .Label string.
Additional advice: The .Label property is what you see displayed on the Button. It may not be the bset place to pass additional information. The object inspector working on any control also has a line titled 'Additional information' under the tab General which is more appropriate for the purpose. However you need to know that the model's property giving access to that information (string) is .Tag in the API.

===Edit1 2019-02-06 23:08 (UTC+1:00)===
I did a bit more meanwhile because I got interested in the question requiring probably an approach from a somehow theoretical starting point.
For programmers of user code it is a well known annoying problem to pass parameters to subroutines needing to be called via >Tools>Macros>Run or by an event raised by MouseClick on a sensitive area. Using Calc I prefer cell ranges for the purpose. Working with text douments TextTable can be a (uncomfortable) surrogate.
It's different and much more complicated if there shall be used "many" FormControl, most Likely of PushButton type. To a first view it seems unavoidable to edit every single button pasing information to the Sub to call via the .Tag (or .Label ??) property e.g.
I wanted to find a way to simply create one such button associated with one Sub (that will have to select cases internally), to copy this button and paste it into (e.g) the cells of a table column, and to take the needed additional information after the event raising action from an adjacent column then.
It was a bit challenging, and it isn't satisfyingly efficient. I nonetheless attach this example demonstrating how to do it in prínciple. The included Sub for the disambiguation of control names may be of some interest independent of this special question.

Of course I am interested in solutions proving my attempt unnecessarily complicated.

edit flag offensive delete link more


HI Using the source.model would appear to be ideal, but I cannot find anyway/examples of this property. DO you have any examples? Spent hrs googling and getting nowhere, probably seraching for the wrong thing.

josh2008 gravatar imagejosh2008 ( 2019-02-06 14:04:58 +0100 )edit

Sorry I don't understand what you expect as an "example for source.model". I described the way to get access to subordinate properties like .Label and .Tag. The "model" itself is a way to talk_of/access the FormControl object having raised the event.
If I find the time I will attach a basic example for a TextDocument containing a button and a Sub called by clicking on it.

Lupp gravatar imageLupp ( 2019-02-06 14:37:11 +0100 )edit

answered 2019-02-06 22:56:45 +0100

josh2008 gravatar image

updated 2019-02-06 23:00:01 +0100


I worked out the following and it seems to work for my needs;

Sub My_Remote(oEvent)
sName = oCaller.Name
sLabel = oCaller.Label
shell("my_remote.exe " & sLabel,6)
End Sub
edit flag offensive delete link more


I still would emphasize that the .Tag property is appropriate for the purpoise. This does not prohibit, of course, to also show part (or all) of this informartion via the .Label to the user.

Lupp gravatar imageLupp ( 2019-02-06 23:13:26 +0100 )edit

I use the label as this shows the actual commands that are being sent to the external application. It makes it visually easier to understand.

josh2008 gravatar imagejosh2008 ( 2019-02-06 23:20:47 +0100 )edit

Of course. (I could anticipate this reason.) You have to do as your needs require.
However, you need to edit your "loads of push buttons" one by one this way, won't you?
Users more acquainted with spreadsheets or databases tend to think of lookup tables for related purposes.

Lupp gravatar imageLupp ( 2019-02-06 23:24:30 +0100 )edit

Its a Office Writer Document. Its more of an in house instructional manual, that a user can read about a device(s) function; if they press the button that has the command on it, it then sends this to the remote app, which in turns communicates with other application/devices to demo/test that function. As it stands, I can now just copy paste a Button, change its label to match the function its going to send and bingo.

josh2008 gravatar imagejosh2008 ( 2019-02-06 23:45:47 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-02-06 02:43:56 +0100

Seen: 219 times

Last updated: Feb 06 '19