The 5 Steps to Creating an OpenOffice Macro

How to Start Writing OpenOffice.org Macros in just Five Simple Steps

© Mark Alexander Bain

Jul 30, 2008
OpenOffice Macros can appear intimidating to start with, but they're not - in just five easy steps any user can start developing their own macros.

It's quite often that users moving from Microsoft Office to OpenOffice.org may want to start writing macros but are put off by the apparently complexity of doing so; and that's a shame, because it's neither difficult, nor complicated. In fact, there are just five simple steps to writing any OpenOffice Macro.

Step 1: Starting OpenOffice

OpenOffice has its own built in programming language (Basic) and its own built in IDE (Integrated Design Environment). The first step, therefore, is for the user to start OpenOffice by either:

  • selecting OpenOffice or one of the OpenOffice applications (e.g. Calc or Writer) from the desktop menu
  • starting OpenOffice from the command line by calling the application by name - for instance typing soffice or ooffice (depending on the operating system and version of OpenOffice being used - and in some cases the full path may be needed as well)

Step 2: Starting the IDE

Having started OpenOffice then next step is to start the IDE - and this can be done from the OpenOffice menu by clicking on:

  • Tools
  • Macros
  • Organize Macros
  • OpenOffice.org Basic

Step 3: Choosing Where to Save the Macro

This is actually the most off-putting stage - not because it is difficult, but because it uses terms that the new user may find confusing. The user is presented with a few possible locations in which to create a macro:

  • My Macros - this is the default location for all new macros
  • OpenOffice.org Macros - although this area is listed users are not actually allowed to save macros there; it is purely for system macros, not user macros
  • an open document - if any documents are open then the macro can be saved there rather than My Macros

Obviously there is only a choice between My Macros and one of the documents, but which should the user choose? To make that decision there is a simple rule of thumb:

  • If the macro is to be used in a number of documents, and those documents are only going to be accessed by the macro developer then use My Macros, but if the document and the macros are to be passed on to other users then save in the document itself

Step 4: Libraries and Modules

As well as deciding which area to save the macro in, the user must decide which library and which module the macro should be in, and to do that they must understand what a library or a module is:

  • modules are files used to store groups of macros
  • libraries are directories (or folders) for storing groups of modules

Tip: It is tempting for the new user to allow OpenOffice to name all of the libraries and modules, but this should be avoided. It is better for the user to get into the habit of naming libraries and modules appropriately - giving them names that will still mean something in six months or a year. So rather than Library1 and Module1 use something like libGlobalDomination and modFinancialWizard.

Step 5: The Macro Itself

Finally the macro can be written - in fact OpenOffice kindly writes one for the new user. Unfortunately it doesn't do anything - it's just a dummy macro:

Sub Main

End Sub

However, it does show how Subs (subroutines) should be defined, and this can quickly be modified to create the user's first (and obligatory) Hello World macro:

Sub Main

msgbox "Hello World"

End Sub

And so, with just 5 steps an average OpenOffice user can be turned into a full blown computer geek.


The copyright of the article The 5 Steps to Creating an OpenOffice Macro in Office/Business Software is owned by Mark Alexander Bain. Permission to republish The 5 Steps to Creating an OpenOffice Macro 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