Using Form Controls in LibreOffice Macro

2 min


This tutorial will use the form controls such as a button inside LibreOffice Calc spreadsheet and assign a macro which will fire when the button is clicked. This is a simple tutorial depicting the basics, you can extend it to your other needs.

Adding a button to Calc spreadsheet

LO_Form_Controls_1

To open up the form controls, go to View -> Toolbars -> Form Controls. The form control consists of various common controls, a toggle button of design mode etc.

LO_Form_Controls_2

We would now add a button to the Calc spreadsheet using the button control.

Before we assign any macro i.e. when the button is clicked to do something, let write a simple program in basic which will execute when the button is pressed. For more details on how to create a macro click here for a detailed tutorial.

Program that will fire when button is clicked

Sub hello_world

	dim my_doc   as object
	Dim my_sheets as object
	Dim my_cell as object
	
	my_doc = ThisComponent
	my_sheets = my_doc.Sheets 

	my_cell = ThisComponent.Sheets(0).getCellByPosition(2,2)

	my_cell.String = "A string populated by a button!"

	Msgbox "~~~ Welcome ~~~" & chr(13) & "LibreOffice Form Controls Demo",,"DebugPoint.com"

End Sub

Once the program is ready, go back to the Calc spreadsheet and select the button. Click the ‘Controls’ button on the Form Controls toolbar (See above image – the button mentioned as Properties) OR you can right-click the button and click Controls from context menu.

LO_Form_Controls_3

A properties window will open for the button.

Assign a macro to the button click

LO_Form_Controls_4

Click on the small button beside ‘Execute action’ label. A new window, ‘Assign Action’ would open. Choose the even ‘Execute Action’ and click the button ‘Macro’ to select a macro.

LO_Form_Controls_5

Now, choose your desired macro to be executed (for this tutorial, which is ‘hello world’) and click ok.

LO_Form_Controls_6

Upon selecting the macro, you would see the chose macro appears in the ‘Assign Action’ window. Click ok to return to the spreadsheet.

SEE ALSO:   Form Processing with LibreOffice Calc Macro - Part 2

Running the macro

LO_Form_Controls_7

Now it’s time to run, but before that turn off the design mode by clicking the ‘Design Mode On/Off’ button on the Form Controls toolbar. Once that is done, click the button and see the result.

This way, you can quickly assign macros to controls and automate various tasks in LibreOffice.

Looking for Something Else?

If you are looking for something else in LibreOffice macro tutorials, Or, wants to learn more about it, please follow below link for complete Macro Tutorials Index:

LibreOffice Macro Tutorial Index


We bring the latest tech, software news and stuff that matters. Stay in touch via Telegram, Twitter, YouTube, and Facebook and never miss an update!

Join our Telegram channel and stay informed on the move.

Also Read


Like it? Share with your friends!

Arindam

Creator of debugpoint.com. All time Linux user and open-source supporter. Connect with me via Telegram, Twitter, LinkedIn, or send us an email.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x