A Write macro tutorial

This tutorial will show how to build a macro for a standard way of closing a letter (the "yours sincerely" bit).

  1. In Write, create a new macro: select Tools/Macro/Macros

  2. Type in "LetterClosing" in the "Macro Name:" box.

  3. Click on the Create button.

You are now presented with the following:

Sub LetterClosing()

' Put macro code here

End Sub

Sub is short for subroutine and the name you entered follows it. This is the standard way of declaring a macro. The very last line of your subroutine is "End Sub". An error is generated if this is missing.

The line in-between begins with an apostrophe. You can put as much descriptive text into the macro as you want - just begin the line with an apostrophe. For now, you can delete the "Put macro code here"

Let's start with the simple problem of inserting some text, somewhere.

The macro command for inserting text is simply "Insert". But this is not enough on its own. You need to know that "Insert" belongs to something called "Text", which is the entire text of your document. How about "which document" - you could have several documents open so you need to specify which one. You could do this by name, but this would make the macro rather too specific. What you really want is to have it work with the currently active document. The way to refer to this is "ActiveDocument". So a command to insert text is as follows:

ActiveDocument.Text.Insert

What we've been describing is part of the "object model" for Ability.

To finish off, you need to specify what to insert and where to insert it, in the format:

ActiveDocument.Text.Insert position, text

where position is the number of characters from the beginning of the document and text is the actual text to insert. So:

ActiveDocument.Text.Insert 0, "Hello from Ability"

would insert "Hello from Ability" at the start of your document (the reference to position is zero based) and your complete macro will now look like this:

Sub LetterClosing

ActiveDocument.Text.Insert 0, "Hello from Ability"

End Sub

Lets run the macro to see what happens:

  1. Select a Write document (use the Windows menu).

  2. Select Tools/Macro/Macros.

  3. You'll see "LetterClosing " as a named macro - click on it to select it.

  4. Click on the "Quick macro" checkbox so a tick appears (we'll see why in a minute).

  5. Click the Run button to execute the macro.

The text should appear at the start of your document. In step 4. above, we asked Ability to remember the macro as a "Quick macro" - this means it will appear on the shortcut menu as follows:

  1. Put the mouse pointer over the document and right-click.

  2. Select Macros.

  3. You'll see the LetterClosing macro available - select it.

The text will be inserted again at the beginning of the document.