1. Technology

Learn VBA Macro Coding with Word 2007 - A "From the Ground Up" Tutorial

Part 1 of an About Visual Basic Tutorial


Updated May 16, 2014

About this course ...

The goal of this course is to help people who have never written a program before learn to write one. There's no reason why office workers, homemakers, professional engineers and pizza delivery persons shouldn't be able to take advantage of their own hand crafted custom computer programs to work faster and smarter. It shouldn't take a 'professional programmer' (whatever that is) to do the job. You know what needs to be done better than anyone else. You can do it yourself!

(And I say this as someone who has spent many years writing programs for other people ... 'professionally'.)

With that said, this is not a course in how to use a computer.

This course assumes that you know how to use popular software and in particular, that you have Microsoft Word 2007 installed on your computer. You should know basic computer skills like how to create file folders (that is, directories) and how to move and copy files. But if you've always wondered what a computer program actually was, that's OK. We'll show you.

Microsoft Office isn't cheap. But you can get more value from that expensive software you already have installed. That's a big reason we use Visual Basic for Applications, or VBA, along with Microsoft Office. There are millions who have it and a handful (maybe no one) who uses everything it can do.

Before we go any further, however, I need to explain one more thing about VBA. In February 2002, Microsoft made a 300 billion dollar bet on a totally new technology base for their entire company. They called it .NET. Since then, Microsoft has been moving their entire technology base into VB.NET. VBA is the very last programming tool that still uses VB6, the tried and true technology that was used before VB.NET. (You'll see the phrase "COM based" to describe this VB6 level technology.)


Microsoft has created a way to write VB.NET programs for Office 2007. It's called Visual Studio Tools for Office (VSTO). The problem with VSTO is that you have to buy and learn to use Visual Studio Professional. (A copy will set you back $690.00 from Amazon at the time this article was written.) Excel itself is still COM based too and .NET programs have to work with Excel through an interface (called the PIA, Primary Interop Assembly).

So ... until Microsoft gets their act together and gives you a way to write programs that will work with Word and doesn't make you join the I/T department, VBA macros are still the way to go.

Another reason we use VBA is that it really is a 'fully baked' (not half baked) software development environment that has been used for years by programmers to create some of the most sophisticated systems in existance. It doesn't matter how high your programming sights are set. Visual Basic has the power to take you there.

What is a macro?

You may have used desktop applications that support what is called a macro language before. Macro's are traditionally just scripts of keyboard actions grouped together with one name so you can execute them all at once. If you always start the day by opening your "MyDiary" document, entering today's date, and typing the words, "Dear Diary," -- Why not let your computer do that for you? To be consistent with other software, Microsoft calls VBA a macro language too. But it's not. It's much more.

Many desktop applications include a software tool that will let you record a "keystroke" macro. In Microsoft applications, this tool is called the Macro Recorder, but the result is not a traditional keystroke macro. It's a VBA program and the difference is that it does not simply replay the keystrokes. A VBA program gives you the same end result if possible, but you can also write sophisticated systems in VBA that leave simple keyboard macros in the dust. For example, you can use Excel functions in Word using VBA. And you can integrate VBA with other systems like databases, the web, or other software applications.

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. That's what we're going to do.

Start Microsoft Word 2007 with a blank document and get ready to write a program.

  1. About.com
  2. Technology
  3. Visual Basic

©2014 About.com. All rights reserved.