Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic
Write A Program!
2 - Programmers, Start Your Recorders!
 Lesson 1
Write A Program

1 - Ready! Set! Go!

2 - Programmers, Start Your Recorders!

3 - Check Out The Macro

4 - Running The Macro

5 - What Could Go Wrong?

6 - OK ... Now What's Next?


At this point, you should have started Word 2000 with a blank document. We're going to use the VBA Macro Recorder to create your first program.

A macro is just a name for a bundle of keyboard commands that are stored together in the same file. Many desktop applications include a software tool that will let you record a sequence of commands in a program and save them as a macro. In Microsoft applications, this tool is called the Macro Recorder. The Microsoft Office applications that can do this trick are Word, Excel, PowerPoint and Project. Although the VBA Macro Recorder is very useful for simply creating simple keyboard macros, programmers have discovered that it's even more useful to give them a running start in more sophisticated programs. We'll see why in this lesson.

  1. Open the VBA Editor and start the Macro Recorder. (Use the Menu command: Tools > Macro > Record New Macro.)

  2. Saving the Macro

  3. Name your macro: AboutVB1 by typing that name in the Macro Name textbox.
  4. Select Document1(document) as the location to store your macro and click OK. See the example above.
  5. (Note: If you pick All Documents(Normal.dot) from the drop down menu, this test VBA program will, in effect, become a part of your Word system. Normal.dot is the default so you must change it. 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, save the macro in the document.)

  6. Create a Word document with this content:

    Hello World.

  7. (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.)

  8. Stop the Macro Recorder by clicking the Stop icon in the Macro Control dialog window. See the illustration below.


  9. Stop Macro Recorder
  10. Close Word and save the document using this name: AboutVB1.doc.

That's it! You have now written a Word VBA program. We'll see what it looks like in the next section:

3 - Check Out The Macro

Explore Visual Basic

By Category

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.