Message Box (Excel VBA) For Beginners
In Previous Article "My First VBA Code (Macro)" we have learnt, how to create Message Box or How to write first VBA Codes which gives a brief idea to about how to start writing Macro/VBA Codes in Visual Basic for Applications.
This article help the user to learn details of Message Box which can play an important role in a program.
Message Box is a dialog box containing messages/information for users to respond, it returns with an Integer value indicating which button the user has clicked. It intensively use in all programs and give directions to program. it can be linked with various conditions in coding.
Watch Video
Here is the Syntax for Message Box:
Msgbox(Prompt,[Buttons],[Title],[helpfile],[context])
Syntax
|
Requirement
|
Description
|
prompt
|
Yes
|
- Its a string expression displayed as the
message in the dialog box. Maximum length 1024 characters.
|
buttons
|
No
|
- Type of buttons to display, the icon style
to use, the identity of the default button, and the modality of the message
box. Each button has a numeric Value. If omitted, the default value for
buttons is 0.
|
Title
|
No
|
- It’s a String expression displayed in the
title bar of the dialog box. If you omit title, the application name is placed in the title bar.
|
helpfile
|
No
|
- It’s a String expression that identifies
the Help file to use to provide context-sensitive Help for the dialog box. If
helpfile is provided, context must also be provided.
|
context
|
No
|
- Numeric expression that is the Help
context number assigned to the appropriate Help topic by the Help author. If context is provided, helpfile must also be provided.
|
The Buttons Argument Setting: You can choose following options for your Message Box.
Settings/Properties
|
Value
|
Description
|
vbOKOnly
|
0
|
- Display OK button only
|
vbOKCancel
|
1
|
-
Display OK and Cancel buttons
|
vbAbortRetryIgnore
|
2
|
- Display Abort, Retry, and Ignore buttons
|
vbYesNoCancel
|
3
|
-
Display Yes, No, and Cancel buttons
|
vbYesNo
|
4
|
- Display Yes and No buttons
|
vbRetryCancel
|
5
|
-
Display Retry and Cancel buttons
|
vbCritical
|
16
|
- Display Critical Message icon
|
vbQuestion
|
32
|
-
Display Warning Query icon
|
vbExclamation
|
48
|
- Display Warning Message icon
|
vbInformation
|
64
|
-
Display Information Message icon
|
vbDefaultButton1
|
0
|
- First button is default
|
vbDefaultButton2
|
256
|
- Second
button is default
|
vbDefaultButton3
|
512
|
- Third button is default
|
vbDefaultButton4
|
768
|
- Fourth
button is default
|
vbApplicationModal
|
0
|
- Application modal; the user must respond
to the message box before continuing work in the current application
|
vbSystemModal
|
4096
|
- System
modal; all applications are suspended until the user responds to the message
box
|
vbMsgBoxHelpButton
|
16384
|
- Adds Help button to the message box
|
VbMsgBoxSetForeground
|
65536
|
-
Specifies the message box window as the foreground window
|
vbMsgBoxRight
|
524288
|
- Text is right aligned
|
vbMsgBoxRtlReading
|
1048576
|
-
Specifies text should appear as right-to-left reading on Hebrew and Arabic
systems
|
Buttons Return Values: Following are the return values which give information that which button is pressed
Button
|
Integer Value
|
Description
|
vbOK
|
1
|
OK
|
vbCancel
|
2
|
Cancel
|
vbAbort
|
3
|
Abort
|
vbRetry
|
4
|
Retry
|
vbIgnore
|
5
|
Ignore
|
vbYes
|
6
|
Yes
|
vbNo
|
7
|
No
|
You can share your feedback and post your excel queries in this blog.
No comments:
Post a Comment