128 Create and Use a Macro

 <  Day Day Up  >  

When you find yourself performing the same series of keystrokes over and over, perhaps in a series of menu selections or dialog box selections, you should store those keystrokes in a macro. Once the keystrokes are recorded in a macro, you can easily repeat them simply by requesting the macro.

Before You Begin

127 About OpenOffice.org Macros


See Also

132 Associating OpenOffice.org and Microsoft Office Files


You can request that an OpenOffice.org program run a macro by setting up a graphic image or by specifying that the macro run when you point to an object with your mouse. Actually, OpenOffice.org supports several ways to trigger the execution of a recorded macro, including the following:

  • Pressing a key combination that you assign to the macro

  • Clicking an object such as a graphic image

  • Moving the mouse over or away from an object

  • Clicking a hyperlink you've assigned to a macro

  • Loading of a graphic image

  • Typing of certain text

  • Selecting a macro to run from the Macro dialog box

  • Resizing or moving a frame around an object

NOTE

graphics/notebw_icon.gif

This list is not exhaustive; OpenOffice.org supports several additional ”but more advanced ” methods of macro execution.


  1. Start Recording a Macro

    Once you've determined that you want to automate mouse clicks, mouse movements, or keystrokes to store as a macro, select Tools, Macros, Record Macro to start recording the macro. The small Record Macro dialog box appears with a single button on it, labeled Stop Recording . You now must walk through the actions that you want OpenOffice.org to record. Once you've finished the final keystroke, click the Stop Recording button and save the macro before specifying how it is to be executed.

    graphics/17inf01.jpg
  2. Perform Keystrokes in the Macro

    Perform all the keystrokes that you want in this macro. For example, if you have to use special bullets in some reports , you can create a macro that not only begins a bulleted list but also selects the appropriate bullet symbol to use (as opposed to the default bullet symbol that normally appears). Such a macro would require that you click the Bullets On button on the Object toolbar, select the Format, Numbering/Bullets menu option, click the Graphics tab to display the Graphics page, click the symbol you wish to use for the bulleted list, and finally click the OK button to close the dialog box.

    NOTE

    graphics/notebw_icon.gif

    You can use the Macro dialog box to save or to execute previously saved macros.

    Once you've finished with all the keystrokes, menu traversal, and dialog box selections, click the Stop Recording button to inform OpenOffice.org that you're through adding keystrokes to the macro. The Macro dialog box appears.

  3. Name and Save the Macro

    Type a name for your macro in the Macro name text box. You can select a different location to store the macro from the default location, named Standard , but for most macros, the Standard library is an appropriate place to store your macro. You can create new libraries of related macros. Click the New Library button to add a new library to the collection. Click Save to store your macro under the name you assigned to it.

    You now can execute the macro without having to repeat those same series of keystrokes ever again. Your macro will be listed in the library where you saved it. In addition, the Macro dialog box now contains additional buttons .

    Click the Assign button to open the Configuration dialog box, where you can determine how the macro is to be triggered in the future. Click the Keyboard tab to display the Keyboard page. Here, you can assign a shortcut key that will trigger your macro.

    KEY TERM

    graphics/newtermbw_icon.gif

    Shortcut key ” A keystroke, such as Ctrl+B , that performs an action, such as formatting selected text, or executes a macro.

  4. Assign the Macro to an Event

    Perhaps the most straightforward way to execute a macro's keystroke instructions is to assign the macro to a shortcut key combination that you don't use for other commands. For example, Shift+F3 isn't used throughout all of OpenOffice.org, so you could assign that keystroke to your macro.

    NOTES

    graphics/notebw_icon.gif

    If you had not first located your macro, OpenOffice.org could not have known you were assigning the macro you just created to a shortcut key. An argument can be made that because you just created the macro, OpenOffice.org should already have that macro selected for you when you get to the Keyboard page of this dialog box.

    You can reassign some of the shortcut keys already defined by OpenOffice.org. For example, you can reassign the Ctrl+A (Select All) keystroke so your macro executes in place of the shortcut key's original intent. If the Keyboard page's Modify button is active when you select a shortcut key from the list, you can assign that keystroke to your macro.

    Before selecting a shortcut key for your macro, first locate the macro in the Category and Function sections of the Configuration dialog box. Scroll the Category list until you see your macro's category, which in this and most cases (unless you stored your macro in a different library in step 3) will be inside the OpenOffice.org BASIC Macros section. Click the plus sign to expand the libraries shown in the OpenOffice.org BASIC Macros library section and then click to expand the Standard library collection. Click the Module1 library, and your macro (possibly along with others) will appear in the Function section to the right. Click to select your macro, and now you will assign a shortcut keystroke to that macro.

    In the upper-right corner of the Keyboard page, you can select either the OpenOffice.org option or the application you've just created the macro in (such as Writer), and the list of shortcut keys shown in the Shortcut keys list changes. You can scroll through the list to see which keys are already assigned and which are not. By selecting either the OpenOffice.org option or your specific application, you inform OpenOffice.org that you're assigning this macro to a keystroke either globally across all OpenOffice.org programs or only in your current program (such as Writer).

    Now that you've located and selected your macro, scroll the Shortcut keys list until you locate a shortcut key that is either not assigned or one you want to reassign to your macro. When you click the Modify button, OpenOffice.org assigns your macro to that shortcut keystroke.

    The other tabs on the Configuration dialog box control other macro triggers. For example, the Menu page enables you to assign macros to menu commands that already exist or even to new menu commands that you want to add yourself. The Status Bar page determines what you want to appear on the status bar, such as the current date and time if you wish (although it's slightly odd that OpenOffice.org's designers would have put this page among these other commands). The Toolbars page determines which toolbars appear, and you can click the Customize button to change the buttons on the toolbars and to assign your own macros to the buttons. The Events page is where you can assign macros to specific events, such as moving and clicking your mouse over images and other triggers. For example, if you want a macro to run every time you create a new Writer document, click the Writer option, locate your macro from the Macros libraries, and select Create Document from the list of events at the top of the dialog box. When you click Assign , your macro will run every time you create a new Writer document.

    If you click Save , OpenOffice.org displays the Save Keyboard Configuration dialog box, where you can save the current collection of keystrokes. The Load button loads previously saved keystrokes. If you share OpenOffice.org with other workers, you might want to develop your own macros and keyboard combinations. You aren't limited to macros for new shortcut key assignments; you can, for example, scroll through the Category and Function sections to locate virtually any menu or keystroke action available inside OpenOffice.org, such as the boldface formatting command, and assign that action to another shortcut key. However, once you begin reassigning several keystrokes, others that use OpenOffice.org can very well be confused when their regular keys stop working as expected! So you'll want to save and load your collection of keystrokes and macros before you use OpenOffice.org and then click Reset to reassign everything back to its original, default state once you've finished working. You can click OK to close the Keyboard page and the Configuration dialog box.

  5. Test Your Macro

    Never assume your macro works until you've tested it, preferably several times in several different situations. Depending on what is selected at the time you start your macro, you may find that your macro overwrites data. For example, if you've written a macro to start a bulleted list using a special graphic bullet symbol, when you select text right before you run your macro, the bullet may very well overwrite that selected text. If so, you may want to rerecord the macro so that the first keystroke you press is the Esc key, just to ensure that any previously selected text is unselected before the macro runs. Some macros, however, you create to work on selected text or to work after you select menu options, so you won't always want to start them with the Esc keystroke. Test your macro in all possible situations where you might use it to help ensure that you've written the most accurate macro possible that does exactly what you want done.

 <  Day Day Up  >  


Sams Teach Yourself OpenOffice.org All In One
Sams Teach Yourself OpenOffice.org All In One
ISBN: 0672326183
EAN: 2147483647
Year: 2003
Pages: 205
Authors: Greg Perry

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net