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.
Table of Contents
Adding a button to Calc spreadsheet
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.
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.
A properties window will open for the button.
Assign a macro to the button click
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.
Now, choose your desired macro to be executed (for this tutorial, which is ‘hello world’) and click ok.
Upon selecting the macro, you would see the chose macro appears in the ‘Assign Action’ window. Click ok to return to the spreadsheet.
Running the macro
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: