Macro organization

From Apache OpenOffice Wiki
Jump to: navigation, search

In, macros are grouped in modules, modules are grouped in libraries, and libraries are grouped in library containers. A library is usually used as a major grouping for either an entire category of macros, or for an entire application. Modules usually split functionality types such as user interaction and calculations. Individual macros are subroutines and functions.

Macro Library hierarchy.

A computer scientist would use the figure below to precisely describe the situation. The text “1..*” means one or more, and “0..*” means zero or more. The black triangle means composed of or contains.

  • A library container contains one or more libraries, and each library is contained in one library container.
  • A library contains zero or more modules, and each module is contained in one library.
  • A module contains zero or more macros, and each macro is contained in one module.
Macro Library hierarchy.

Use Tools > Macros > Organize Macros > Basic to open the Basic Macros dialog. All available library containers are shown in the Macro from list. Every document is a library container, capable of containing multiple libraries. The application itself acts as two library containers, one container for macros distributed with called Macros, and one container for personal macros called My Macros. As shown below, only two documents are currently open.

Library containers are shown on the left.

The Macros are stored with the application runtime code, which may not be editable to you unless you are an administrator. This is just as well since these macros should not be changed and you should not store your own macros in the OOo container.

Unless your macros are applicable to a single document, and only to a single document, your macros will probably be stored in the My Macros container. The My Macros container is stored in your user area or home directory.

If a macro is contained in a document, then a recorded macro will attempt to work on that document; primarily because it uses “ThisComponent" for its actions.

Every library container contains a library named Standard. It is better to create your own libraries with meaningful names than to use the Standard library. Not only are meaningful names easier to manage, but they can also be imported into other library containers whereas the Standard library cannot.

Documentation caution.png allows you to import libraries into a library container, but it will not allow you to overwrite the library named Standard. Therefore, if you store your macros in the Standard library, you cannot import them into another library container.

Just as it makes good sense to give your libraries meaningful names, it is prudent to use meaningful names for your modules. By default, uses names such as Module1. Feel free to use your own meaningful name.

As you create your macros, you must decide where to store them. Storing a macro in a document is useful if the document will be shared and you want the macro to be included with the document. Macros stored in the application library container named My Macros, however, are globally available to all documents.

Macros are not available until the library that contains them is loaded. The Standard library and Template library, however, are automatically loaded. A loaded library is displayed differently from a library that is not loaded. To load the library and the modules it contains, double-click on the library.

Where are macros stored? stores user-specific data in a directory under the user's home directory. For example, on Windows, this is C:\Documents and Settings\<name>\Application Data. User macros are stored in OpenOffice.org2\user\basic. Each library is stored in its own directory off the basic directory.

It is not important to understand where macros are stored for casual use. If you know where they are stored, however, you can create a backup, share your macros, or inspect them if there is an error. For example, on one or more of my upgrades, all of my macros disappeared. Although the macros were still on disk, the macros were not copied to the new directories. The solution was to import the macros into the new installation.

Use Tools > Macros > Organize Dialogs to open the Macros organizer dialog. Another common way to open this dialog is to use Tools > Macros > Organize Macros > Basic to open the Macros dialog and then click the Organizer button (see Figure 6).

Figure 6: The Libraries tab of the Macro Organizer dialog.

Importing macros

The Macro Organizer dialog provides functionality to create, delete, and rename libraries, modules, and dialogs. Select the library container to use and then click the Import button to import macro libraries.

Select a macro library to import.
Tip.png You cannot import the library named Standard.

Tip.png On Linux, the files are stored in a directory whose name begins with a period. Directories and files with names beginning with a period are not shown in a normal selection dialog. To open the directory, I navigated to the parent directory, entered the name .openoffice.org2, and then clicked Open. This opened the directory, which was not initially shown.

Navigate to the directory containing the library to import. There are usually two files from which to choose, dialog.xlb and script.xlb. It does not matter which of these two files you select; both will be imported. Select a file and click Open to continue.

Choose library import options.

If the library already exists, it will not be replaced unless Replace existing libraries is checked. If Insert as reference is checked, the library is referenced in its current location, but you cannot edit the library. If Insert as reference is not checked, however, the library is copied to the user's macro directory.

Macros can be stored in libraries inside documents. Select a document rather than a directory on disk (as shown in Figure 7) to import libraries contained in a document.

Downloading macros to import

Macros are available for download. Some macros are contained in documents, some as regular files that you must select and import, and some as macro text that should be copied and pasted into the Basic IDE; use Tools > Macros > Organize Macros > Basic to open the Macros dialog, choose the macro to edit, and then click Edit to open the macro in the Basic IDE.

Some macros are available as free downloads on the Internet (see Table 1).

Table 1. Places to find macro examples.

Location Description Reference materials regarding macros.    Reference materials regarding database macros.    Lots of links to everything. Many examples and help.
Content on this page is licensed under the Creative Common Attribution 3.0 license (CC-BY).
Personal tools