» Use messageboxes using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Files, Workbook, and Worksheets in VBA
VERSION - All Microsoft Excel Versions
MsgBox "The job is done !"
' messagebox with text and OK-button
MsgBox "The job is done !", vbInformation
' messagebox with text, OK-button and an information-icon
MsgBox "The job is done !", vbCritical
' messagebox with text, OK-button and a warning-icon
MsgBox "The job is done !", vbInformation, "My Title"
' messagebox with text, OK-button, information-icon and a custom title text
Answer = MsgBox("Do you want to continue ?", vbYesNo)
' messagebox with YES- and NO-buttons,
' the result is an integer, the constants are named vbYes and vbNo.
Answer = MsgBox("Do you want to continue ?", vbYesNo + vbQuestion)
' messagebox with YES- and NO-buttons and a question-icon
Answer = MsgBox("Do you want to continue ?", vbYesNo + vbQuestion, "My Title")
' messagebox with YES- and NO-buttons,
' question-icon and a custom title text
Answer = MsgBox("Do you want to continue ?", vbYesNo + 256 + vbQuestion, "My Title")
' messagebox with YES- and NO-buttons, question-icon and a custom title text,
' the NO-button is default
Answer = MsgBox("Do you want to continue ?", vbOKCancel, "My Title")
' messagebox with OK- and CANCEL-buttons, the result is an integer,
' the constants are named vbOK og vbCancel.
The result from the MsgBox-function can be stored in a variable. The variable can be of type Integer.This variable may be used later in the macro code like this:
Answer = MsgBox("Do you want to continue ?", _
vbOKCancel, "My Title")
If Answer = vbCancel Then Exit Sub ' the macro ends if the user selects the CANCEL-button
Or like this:
If MsgBox("Do you want to continue ?", vbOKCancel, _
"My Title") = vbCancel then Exit Sub
Book Store:
Recommended Books:
- Essentials of Accounting and Post Test Booklet 8, Eighth Edition
- Microsoft Excel 2002 Simply Visual
- Treason: Liberal Treachery from the Cold War to the War on Terrorism
- Special Edition Using Microsoft Excel 2002
- The Total Money Makeover. : A Proven Plan for Financial Fitness
- Millionaire Real Estate Mentor : The Secrets of Financial Freedom through Real Estate Investing
No comments have been submitted.

