Objects! (and Methods and Properties)
This is a free tutorial to help non-programmers learn to write a computer program using the language built into Microsoft Word 2007: VBA. You can multiply your productivity in using Word by writing your own software to automate the things you do with Word. Do you have to write letters where only a few things change? Just type in the things that change and let a program write a the letter.
To get the most from this tutorial, you might want to start at the beginning: Part 1 - A "From the Ground Up" Tutorial - Write a Program! Now!
The Word VBA Macro Reconsidered
Pick up just about any "Introduction to Programming" book written in the last twenty years and one of the first few chapters will introduce what are usually called, "control structures." These include "Do loops," "If-Then-Else blocks," and "Case statements." We'll discuss these too, but programming has changed and just learning the programming language and how to write code isn't the most fundamental and important part of programming. The most important thing to learn today is usually called Object Oriented Programming, or OOP. It is absolutely essential that you understand this concept to be a successful Visual Basic programmer, or a programmer using almost any other software technology.
Here's the complete program that was created by the VBA Macro Recorder:
Sub AboutVB1()
'
' AboutVB1 Macro
' Macro recorded 12/7/1941 by Dan Mabbutt
'
Selection.TypeText Text:="Hello World!"
End Sub
The single program statement consists of:
- An object: Selection
- A method: TypeText
- A property: Text
In words, this statement says, Use the TypeText method in the Selection object to add the character string "Hello World!" in the Text property to the current document.
Much of programming these days consists of learning to use objects that have methods and properties that you need to do whatever you want the program to do. We'll see more of these in programming examples later in this course. One of the real advantages of using the Macro Recorder is that it will suggest the right methods and properties for you to use so you don't have to remember them. Often, you can just change a program that has been recorded to do something slightly different to create exactly the program you want.
Since "Hello World" has served as our introduction to OOP, let's get to know it better now.

