OpenOffice.org OpenOffice - 3.3 Guide de démarrage rapide Page 323

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 379
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 322
Your first macros
A macro is a saved sequence of commands or keystrokes that are stored for later use.
An example of a simple macro is one that “types” your address. The OpenOffice.org
macro language is very flexible, allowing automation of both simple and complex
tasks. Macros are especially useful to repeat a task the same way over and over
again.
OpenOffice.org macros are usually written in a language called StarBasic, or just
abbreviated Basic. Although you can learn Basic and write macros, there is a steep
learning curve to writing macros from scratch. The usual methods for a beginner are
to add macros that someone else has written and to use the built-in macro recorder,
which records your keystrokes and saves them for use.
Most tasks in OpenOffice.org are accomplished by “dispatching a command” (sending
a command), which is intercepted and used. The macro recorder works by recording
the commands that are dispatched (see “The dispatch framework” on page 332).
Adding an existing macro
The first step in learning macro programming is to find and use existing macros. This
section assumes that you have a macro that you want to use; the macro may be in an
email, on a web page, or even in a book. For this example, use the macro in Listing 1.
Listing 1: Simple macro that says hello.
Sub HelloMacro
Print "Hello"
End Sub
You must create a library and module to contain your macro; this is covered in
“Macro organization” on page 333. Use these steps to create a library to contain your
macro:
1) Use Tools > Macros > Organize Macros > OpenOffice.org Basic to open
the OOo Macro dialog (see Figure 300 and Figure 305).
2) Click Organizer to open the OOo Basic Macro Organizer dialog (see Figure
306).
3) Select the Libraries tab.
4) Set the Location to My Macros & Dialogs, which is the default.
5) Click New to open the New Library dialog. Enter a library name such as
“TestLibrary” and click OK.
6) Select the Modules tab.
7) In the Module list, expand My Macros and select TestLibrary. A module named
Module1 already exists and can contain your macro. You can click New to
create another module in TestLibrary.
8) Select the Module1, or the new module that you created, and click Edit to
open the OOo Integrated Debugging Environment (IDE).
9) The IDE is a text editor for macros that allows you to edit and create macros.
Copy the macro into the IDE.
When a new module is created, it contains a comment and an empty macro named
Main, that does nothing.
Chapter 13 Getting Started with Macros 323
Vue de la page 322
1 2 ... 318 319 320 321 322 323 324 325 326 327 328 ... 378 379

Commentaires sur ces manuels

Pas de commentaire