OpenOffice.org/Macro

From Wikibooks, open books for an open world
Jump to navigation Jump to search

If you want to perform a repetitive task, doing this automatically using a macro is the way to go. A macro is a series of instructions for the computer to perform. Macros are widely used by professionals and expert users in Microsoft Office. OpenOffice.org can also perform macros. OpenOffice.org can be scripted through OpenOffice.org Basic (the easiest and most common language), Python, Beanshell, and Javascript, this feature is more widely known as Macro.

Imagine you have twelve spreadsheets which need your name as a page footer, the top row made bold and the fourth column highlighting in red. How would you do this without going through each one individually? The answer is record a macro.

A simple macro called Main to zoom out to 75% in OpenOffice.org Basic looks like this.

sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Zoom.Value"
args1(0).Value = 75
args1(1).Name = "Zoom.ValueSet"
args1(1).Value = 28703
args1(2).Name = "Zoom.Type"
args1(2).Value = 0

dispatcher.executeDispatch(document, ".uno:Zoom", "", 0, args1())


end sub

External links[edit | edit source]

General Macro help[edit | edit source]