The Developer tab in Word
One of the first things that you have to do to write Visual Basic program in Word 2007 is find Visual Basic! The default in Word 2007 is to not display the ribbon that is used. To add the Developer tab, first click the Office button (the logo in the upper left corner) and then click Word Options. Click Show Developer tab in the Ribbon and then click OK.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
When you click the Developer tab, you have a whole new set of tools used to write VBA programs. We're going to use the VBA Macro Recorder to create your first program. (If the ribbon with all your tools keeps disappearing, you might want to right-click the ribbon and make sure Minimize the Ribbon is not checked.)
Click Record Macro. Name your macro: AboutVB1 by typing that name in the Macro Name textbox. Select your current document as the location to store your macro and click OK. See the example below.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
(Note: If you pick All Documents (Normal.dotm) from the drop down menu, this test VBA program will, in effect, become a part of Word itself because it will then become available for every document you create in Word. If you only want to use a VBA macro in a specific document, or if you want to be able to send it to someone else, it's a better idea to save the macro as part of the document. Normal.dotm is the default so you must change it.)
With the Macro Recorder turned on, type the text, "Hello World." into your Word document. (The mouse pointer will change into a miniature picture of a tape cartridge to show that keystrokes are being recorded.)
(Note: Hello World is almost required for a "First Program" because the very first programming manual for the early computer language "C" used it. It's been a tradition ever since.)
Click Stop Recording. Close Word and save the document using the name: AboutVB1.docm. You have to select a Word Macro-Enabled Document from the Save as Type dropdown.
That's it! You have now written a Word VBA program. Let's see what it looks like!
