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: Using Message Boxes.

Using Message Boxes

Written by Allen Wyatt (last updated October 29, 2020)
This tip applies to Word 97, 2000, 2002, and 2003


When you create macros in Word, you can easily incorporate the use of message boxes. These are typically used to convey information to the user and to get some rudimentary input. You include message boxes by using the MsgBox command. The following portion of a macro creates a very simple message box:

MsgBox "The Macro is Done"

You can also add symbols to your message boxes by including a symbol-type code as part of your MsgBox invocation. These symbols are used extensively in many Windows dialog boxes. The following four types of symbols can be used:

Type Symbol
16 Stop sign
32 Question mark in a circle
48 Exclamation point in a circle
64 Information symbol (lowercase i in a circle)

As an example, let's suppose you wanted to include the exclamation point symbol. This is typically included in dialog boxes as a notice of when something important has happened or is about to happen. To include this symbol in your message box, you would include the following macro code:

MsgBox "Can't run this macro on this text", 48

So far the MsgBox command has been used as a statement, but you can also use it as a function. If you do so, you can use it to get simple input from the user. To make the MsgBox function more useful, Word allows you to display more clickable buttons in the dialog box besides the OK button. This is done by adjusting the type code, which was used for the symbols displayed in the message box. The following are the different button combinations you can display in your message box:

Type Button Types
1 OK, Cancel
2 Abort, Retry, Ignore
3 Yes, No, Cancel
4 Yes, No
5 Retry, Cancel

To use the buttons, you simply add the value of the button type to the value you want used for the symbol. In the previous example, you used the code of 48 to display the exclamation point symbol. If you wanted to also include the Abort, Retry, Ignore buttons, you simply change the code to 50, which is 48 (the symbol code) plus 2 (the button code).

When using buttons in this way, the MsgBox function returns a value indicating which button the user chose. The buttons return, from left to right, -1, 0, and 1. Thus, if you use a button code of 3, then -1 would mean the user chose Yes, 0 would mean No, and 1 would mean Cancel.

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 (1072) 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: Using Message Boxes.

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

Exporting Latitude and Longitude

A handy way to store latitude and longitude values in Excel is to treat them as regular time values. When it comes around ...

Discover More

Adjusting Times for Time Zones

Collect a series of times in a worksheet, and you might need to adjust those times for various time zones. This involves ...

Discover More

Problems with Default Workbook and Worksheet Templates

You can create a default template for both your workbooks and worksheets. These should be placed in the XLSTART folder, ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (menu)

Moving the Insertion Point to the End of a Line

When writing a macro to process the text in a document, you may need to move the insertion point to the end of a line. ...

Discover More

Determining If a Number is Odd or Even

Need to know if a number in a macro is odd or even? It's easy to figure out with the simple calculation shown in this tip.

Discover More

Determining the Upper Bounds of an Array

When working with variables in a macro, you may need to know the upper boundary dimension for an array. This can be ...

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 1 + 1?

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.