Suite101

Automating OpenOffice: Customizing the Toolbar

Improve OpenOffice.org Automization by Adding a Custom Button

© Mark Alexander Bain

Jul 1, 2008
Many tasks can be made much easier by using macros in OpenOffice.org. That process of automation can be improved even more by customizing the OpenOffice.org toolbars.

OpenOffice.org's macro language is quick to learn and and easy to use. In a relatively short time even a brand new user can automate many of the tasks that would have otherwise taken up a large amount of time and effort. However, running the macro can still be laborious, with the user always having to do the following:

  • click on Tools
  • click on Macros
  • click on Run Macros
  • select the right macro (in the correct library and module)
  • click on Run

Fortunately, this can all be done in a single click - by customizing the toolbar; and the aim of this customization is to:

  • place a new button on the toolbar
  • run a defined macro whenever the button is pressed

Writing an OpenOffice.org Basic Macro

Before the toolbar customization can take place a macro must be created by using the OpenOffice.org Basic IDE (Integrated Development Environment); and at this point the less experienced user might want to pause and read the article "Using Macros to Automate OpenOffice.org Calc". The macro can be as complicated or as simple as is necessary, for example, the following macro loads a random number into a selected cell in a Calc spreadsheet:

Sub RandomNumberToActiveCell

oCell = thisComponent.getCurrentSelection

oCell.Value = int ( 10 * Rnd )

End Sub

If this macro is saved into Module1 in the Standard library in the 'My Macros' area then the user can run it by:

  • clicking on a cell in their Calc spreadsheet
  • clicking on Tools
  • clicking on Macros
  • clicking on Run Macros
  • selecting My Macros
  • selecting Standard
  • selecting Module1
  • selecting RandomNumberToActiveCell
  • clicking on Run

Obviously they'd get very bored if they had to do this often, but fortunately, customizing the toolbar will enable them to do this in a single click.

Adding a Button to an OpenOffice.org Calc Toolbar

The process for adding a button for this new macro is quite simple:

  • click on Tools
  • click on Customize
  • select the Toolbars tab
  • select the toolbar to be modified (the default is the standard toolbar)
  • in the Commands pane select the point at which the button is to be added
  • click on Add
  • scroll down to find the macro - in this case:
    • OpenOffice.org Macros
    • My Macros
    • Standard
    • Module1
    • RandomNumberToActiveCell
  • click on Add

A button for the macro will now be displayed on the toolbar; and if the user now selects a cell and presses the new button then a random number will be displayed in the cell as expected. However, anyone looking at this new button will not be impressed at the moment - it works correctly, but the button will just have the word 'RandomNumberToActiveCell' on it.

Changing the Look of the Custom Button

With the macro itself working the user needs to turn their attention to the look of the button that's just been created - in this case changing the button to an icon. They will need to:

  • click on Tools
  • click on Customize
  • select the Toolbars tab
  • select the button for the new macro
  • click on modify
  • click on Change Icon
  • select an appropriate icon or import a new one

The user will now have the button looking the way that they want; doing the job that they want; at their fingertips all of the time; and any task is now 1 click long instead of 8.


The copyright of the article Automating OpenOffice: Customizing the Toolbar in Office/Business Software is owned by Mark Alexander Bain. Permission to republish Automating OpenOffice: Customizing the Toolbar in print or online must be granted by the author in writing.




Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo