Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Understanding Variables.

Understanding Variables

Written by Allen Wyatt (last updated April 20, 2024)
This tip applies to Word 97, 2000, 2002, and 2003


Macros are written in a language called Visual Basic for Applications (VBA). VBA allows you to use quite a few different types of variables. Variables are nothing but names that represent other data. In general, you can store either numbers or characters in VBA variables. The language provides eleven specific types of variables you can use in your macros. These are known as data types, and you should use the data type that most closely matches the characteristics of the information you are storing in the variable. VBA supports the following data types:

  • Byte. A numeric variable within the range of 0 to 255.
  • Boolean. A variable with two possible values: True (-1) or False (0).
  • Integer. A numeric variable designed for whole numbers in the range of -32,768 to 32,767.
  • Long. A numeric variable designed for very large whole numbers.
  • Currency. A numeric variable designed for calculations involving monetary values.
  • Single. A numeric variable designed for single-precision floating-point values; accurate to about six or seven decimal places.
  • Double. A numeric variable designed for double-precision floating-point values; accurate to about 15 decimal places.
  • Date. A numeric variable designed to represent a date and time as a real number. The value to the left of the decimal point is the date, and that portion to the right of the decimal point is the time.
  • String. A variable that can contain any type of text or character you desire. You can assign a maximum of approximately 2 billion characters to a string variable in Word 2000 or later, or approximately 63,000 characters in Word 97.
  • Object. A variable that contains a pointer to a defined object within VBA.
  • Variant. A variable that can contain any type of data.

An additional data type (Decimal) is also specified in the VBA documentation, but is not currently supported by the language. VBA also allows you to define variable arrays, and you can also create user-defined data types. The full range of variable specifications is much too complex for a simple WordTip, however. If you need specific information about how to work with variables, refer to a good Visual Basic or VBA programming book. You can also look in the VBA on-line help under the Dim statement. (The Dim statement is used to declare the data type to be used for a variable.)

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (118) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Understanding Variables.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Controlling Sorting Order

When you sort information either in a table or the body of you document, Word follows a very specific set of rules to do ...

Discover More

Selecting a Specific Cell in a Macro

Need to use a macro to select a specific cell in a different workbook? It's not as straightforward of a proposition as ...

Discover More

Transposing and Linking

Sometimes it is helpful to look at data that is rotated 90 degrees. Excel allows you to use Paste Special to transpose ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (menu)

Quickly Clearing Array Contents

An array of variables is a powerful element of VBA programming. If you want to clear what is stored in an array, here's a ...

Discover More

Swapping Two Numbers

When developing a macro, you may need to swap the values in two variables. It's simple to do using the technique in this tip.

Discover More

Declaring Variables

Declaring variables in a macro is good programming practice. Here's how to do it and how to make sure they are all declared.

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four minus 0?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.