Use Macros to Add a "Replace All" Command

This information was provided by Claris Corporation on 16 March 1998, and incorporated into Apple Computer's Tech Info Library.
Sometimes you want to fill all the fields in the selected set of records with the same value. For example: you just sent bill reminders to several hundred customers. You want to put today's date into the "reminder sent" field for all those records.

Here's how to build a ClarisWorks macro to handle the chore:

1. Create a new ClarisWorks database file with any two fields. Add three empty records. This file lets you use the commands necessary for the macro, without affecting any actual data.

2. Click into any field.

3. Choose Record MacroÉfrom the Macro item of the File menu.

4. Call the new macro "Repeat Loop" and specify the keyboard equivalent Command-Option-r. Click "Record."

5. Type the following key combinations in sequence:
Command-A
Command-V
Command-Return
Command-Option-r
Command-Shift-J

Once you press Command-Shift-J, the macro is finished recording.

6. Again choose Record Macro from the Macro item of the File menu.

4. Call the new macro "Replace All" and specify the keyboard equivalent Command-Option-=.


7. Type the following key combinations in sequence:
Command-A
Command-C
Command-G

At this point, the "Go to Record" dialog box appears. Type the number 1 then press Return.

Continue with the following key combinations:
Command-Option-r
Shift-Command-J

8. Choose Save Macros... from the Macro item of the File menu to store your work on disk.
Whenever you want to use your new "Replace All" command, just click into a field and press Command-Option-=. The contents of that field in every record will be changed to match the value in the current record. When the macro reaches the end of the database, you stop it by pressing Command-Period.

How it works
If you were to manually update the file, you would probably copy the field value you wanted to the clipboard. Then, starting from the first record, you would paste it into the appropriate field in each record. Suppose the cursor was in the field holding the value you wanted replaced throughout the database. Here's the steps you would take by hand:

A. Copy the entire contents of the current field.


B. Go to the same field in the first record.

C. Replace whatever is in the field with what's on the clipboard.

D. Go to the next record.

E. Go to step C.

The first macro sequence you created, in step 5, performs steps C through E. It selects everything in the current field, pastes whatever is in the clipboard, moves to the next record (Command-Return), then calls itself (Command-Option-r). In other words, the last step in the macro is to "type" the keyboard equivalent for itself. This way the macro repeats itself forever or until you press Command-Period to stop it.

The next macro, the one you set up in step 7, sets things up. It's analogous to steps A and B. The macro copies the current field value to the clipboard, then moves to the first record in the found set. (Fortunately, when you use the Go To Record command ClarisWorks doesn't move the insertion point to a different field.) The last step in the macro, Command-Option-r, sets loose the recursive "Repeat Loop" macro through all your records, replacing the data.

Published Date: Feb 18, 2012