OpenOffice.org is fast becoming, if not a replacement then, at least an alternative to Microsoft Office. Like Microsoft Office OpenOffice.org has:
With OpenOffice.org Basic it is possible for anyone to extend the default functionality and automate any essential or repetitive tasks.
Before creating an OpenOffice.org basic macro the new user needs to understand a little about how macros are organized:
Bearing all of this in mind the new user is ready to create their first macro.
OpenOffice.org Basic has its own built in IDE (Integrated Development Environment). So if Calc, for example, is open then the first steps to creating a new macro are:
OpenOffice.org will now display the 'OpenOffice.org Basic Macros' dialog box and the new user must decide which area to use for the macro (i.e. 'My Macros' or the document itself) and then pressing the 'New' button. At this point a new macro will be created and the IDE will open up in edit mode.
It's worth noting that OpenOffice.org always creates a subroutine called 'Main', but this has nothing to do with the 'Main' subroutine seen in programming languages such as C (where 'Main' is the subroutine that is run by default); OpenOffice.org always runs the first macro that it comes to, regardless of its name.
The real strength of the OpenOffice.org Basic macro is when it comes to automating tasks that would otherwise take up valuable time and effort (although it's always worth considering whether or not the time spent coding outweighs the time that it's meant to save); and the required automation can be achieved with relatively few, simple concepts.
Any OpenOffice.org application consists of a number of objects and functions:
The end result is a working macro:
Sub Main
Dim oSheet
oSheet = thisComponent.Sheets(0)
oSheet.getCellRangeByName("A1").String = "Input Data"
oSheet.getCellRangeByName("A2").Value = 4
oSheet.getCellRangeByName("A3").Value = 5
oSheet.getCellRangeByName("A4").Formula = "=A2*A3"
End Sub
The macro is run by pressing the 'Run Macro' button (the one with the green triangle) and (assuming all the lines have been entered correctly) then the spreadsheet will have:
This is, of course, a very simple example, but does show how easily tasks can be automated within OpenOffice.org.