Start Word 2007 again. Step-by-step instructions for creating the macro are below. If you need more help remembering exactly how to do all this, review Part 1 again.
This time we will name the VBA macro AboutFormLetter. The document will be named AboutVB3.docm. If you're new to programming, you might be struggling with how to organize your files on your computer as well. It's a good idea to create a new folder for a project like this to avoid mixing files together and forgetting which is which. Create a new folder somewhere on your computer (you could call it FormLetter or About Visual Basic Project).
Here's some suggested text for your new form letter. We'll use this text later as we complete the macro.
The Form Letter
I'm planning on writing (2) and (Lucky YOU!)
I'm going to give your publishing company the
chance to publish it first! Simply send the
cost of mailing twenty pounds of paper
to the return address on this letter, and
I'll get started writing it right away.
The text (1) and (2) are called placeholders. The VBA macro we will write will replace the placeholders with other text. There are alternative, more sophisticated ways to do this, but this will do the job for now.
Recording the AboutFormLetter macro
To construct the initial macro with the macro recorder, follow the steps below. It's important that you do the steps exactly, because any change will be reflected in the macro that is being recorded. You might have to start over and try it again to get it exactly right. If you do, just click "Yes" when Word asks if you want to replace the existing macro. If you start over, remember to start with the original document that has the (1) and (2) placeholders again.
Click Here to display the illustration
Click the Back button on your browser to return
- Open a new document.
- Save it using the file name AboutVB3.docm. Make sure that it's saved as a "Word Macro-Enabled Document."
- Type the suggested text above into the letter, or type your own letter! Be sure to include the placeholders - (1) and (2) - in the document.
- Save and close the document. We go through this extra step so we can include the "Open" operation into the macro when we turn on the recorder in the next step.
- Turn on the macro recorder. Use the name AboutFormLetter for the macro. Because we closed the document, we can't store it in this document right now. We have to select the Normal template as a place to store the it and plan on moving it later.
- Open the AboutVB3.docm document again.
- Find the text (1) in the document and replace it with "Mr. Publisher Dude".
- Find the text (2) in the document and replace it with the text "the Great Novel of Our Time".
- Close the Find dialog and save the document using the file name AboutVB3_01.docm.
- Turn off the macro recorder.
Now that we have created our initial VBA macro, let's see what we have on the next page.