Using Form Controls in LibreOffice Macro
This tutorial will use the form controls such as 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
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.
Assign a macro to the button click
Running the macro
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: