128. About OpenOffice.org Macros
BEFORE YOU BEGIN
Just jump right in!
129 Create and Use a Macro
The purpose of a macro is to automate any repetitious task that would normally require you to enter a big sequence of commands. OpenOffice.org perceives menu commands, keystrokes, and (in the case of Writer) movements of the mouse pointer, as instructions . When you have OpenOffice.org "record" a macro, what you're asking it to do is watch you perform a series of instructions and then remember that series so that it can repeat it later at your discretion.
Macro A sequence of recorded actions that can be played back at any time, for any number of times, to perform an oft-used, repetitive, or tedious task.
Why would you want the same series of instructions repeated? In most computer applications, you'll often find yourself making the same additions or alterations to different items or to different areas of the document. In Writer, the location of those changes is indicated with the cursor; in Calc, it's the cell pointer. So with each application, you can choose a different thing to change and then have a macro make the same change to it. That's what's so useful about a macronot that it does the same thing in the same way, but that it makes the same series of additions or alterations to whatever you designate .
The type of task you'd record with a macro is most likely something that maybe only you would ever needwhich is why it wasn't built into the OpenOffice.org suite to begin with. For example, suppose that you quite frequently copy selected passages of text from within a Writer document to the end of the document for a summary. You want the copied passage formatted as a bulleted list. You can set up a macro that performs all the commands that make this possibleafter you've already pointed to the copied paragraph in Writer. Such a macro might represent the kind of functionality that you and only a few other users might ever require.
You can record macros only in Writer and Calc.
The macro-recording process is sensitive to three things: the keys you press, the items you click with the mouse (menu commands, toolbar buttons , elements in the document), and the entries you make in dialog boxes. The process does not record your mouse movements , such as "up and to the right." Specifically, the macro recorder isn't concerned with where your mouse pointer is located, as much as with what it's pointing to when you click.
Creating macros is simple. OpenOffice.org learns by example! As 129 Create and Use a Macro shows, when you're ready to create a macro, you only need to tell Writer or Calc to begin recording your next interactions with the program, either from the keyboard or mouse. When you tell the application to stop recording the keystrokes, you name the macro and store it as a file. To run the macro without calling it up as a file (for instance, from some kind of " Open " menu), you can assign some kind of trigger, such as a dedicated keystroke or menu command.
One of the under-appreciated qualities of a macro is not just how it saves time, but how it reduces the chance of user error. When you find yourself performing the same sequence of commands repeatedly, it's possible that you lose track (or lose interest) in what you're doing, slip up, and then find yourself selecting Undo maybe several timesuntil you reset the application to the point before the error occurred. With a properly recorded and debugged macro, you eliminate most chances for errors to crop up because of improper entries.
In Writer, to record the act of selecting a passage of text, such as a word or a paragraph, use keystrokes as described in 4 Type Text into a Document . The recorder does not pay attention to selecting elements with the mouse, but it does record movements of the cursor using the arrow keys and the Shift and Ctrl keys. At such a time, the recorder only takes note of the type of element you're selecting (word, line, paragraph), not the content of the selection ("When in the course of human events ").
As a macro is recorded, the commands you enter are reinterpreted as textual instructions, written in OpenOffice.org's version of the BASIC programming language. You do not have to know anything about BASIC to record macros, nor do you ever have to edit a macro with BASIC to use the macro. However, you do need to know that once they're converted to BASIC, macros are stored in OpenOffice.org using a compartmentalized structure that's meant to help those who actually do use BASIC. This knowledge of something related to a discipline you may never want to know comes into play when you save a recorded macro, and when you assign a recorded macro to a keystroke or toolbar button for playback on demand. So here's the minimum you need to know: