Declaring and Using Variables

Just about any useful macro has to manage data. In VBA, you can work with many different types of data, including text, numbers, and logical data, as well as many custom data types defined in Word. It's often useful to reuse the same data items several times in a single macro. That's where variables come in.

A variable is a temporary storage location for a piece of data. You can think of a variable as a box in which you put the data until you want to come back and use it again. As its name implies, you can also change the value of a variable.

One of the most common operations with a variable is assignment. Using the assignment operator, you can put a value in the variable for later use. The following statement assigns ...

Get Special Edition Using Microsoft® Word 2000 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.