Sub
msg()
dim txt as String
txt = “This is test message!!!”
MsgBox
txt
End
Sub
MsgBox([TEXT], [BUTTONS],
[TITLE])
Sub
delete_A1()
If
MsgBox(
"Are you sure that you
wish to delete the contents of A1 ?"
, vbYesNo,
"Confirm"
) = vbYes
Then
Range(
"A1"
).ClearContents
MsgBox
"The contents of B2 have
been deleted !"
End
If
End
Sub
If
MsgBox(
"Text"
, vbYesNo,
"Title"
) = vbYes
Then
'If
the Yes button is clicked ...
Constant
|
Numerical Value
|
Description
|
vbOKOnly
|
0
|
|
vbOKCancel
|
1
|
|
vbAbortRetryIgnore
|
2
|
|
vbYesNoCancel
|
3
|
|
vbYesNo
|
4
|
|
vbRetryCancel
|
5
|
vbCritical
|
16
|
|
vbQuestion
|
32
|
|
vbExclamation
|
48
|
|
vbInformation
|
64
|
vbDefaultButton1
|
0
|
Default
button : Button 1
|
vbDefaultButton2
|
256
|
Default
button : Button 2
|
vbDefaultButton3
|
512
|
Default
button : Button 3
|
vbApplicationModal
|
0
|
Forces
the user to provide an answer before continuing to use Excel
|
vbSystemModal
|
4096
|
Forces
the user to provide an answer before continuing to use any program on the
computer (dialog box in foreground)
|
MsgBox(
"Text"
, vbYesNoCancel + vbExclamation
+ vbDefaultButton2,
"Title"
)
MsgBox(
"Text"
, vbYesNoCancel + vbExclamation
+ vbDefaultButton2,
"Title"
)
MsgBox(
"Text"
, 3 + 48 + 256,
"Title"
)
MsgBox(
"Text"
, 307,
"Title"
)
Constant
|
Numerical Value
|
Button that corresponds to the numerical value
|
vbOK
|
1
|
|
vbCancel
|
2
|
|
vbAbort
|
3
|
|
vbRetry
|
4
|
|
vbIgnore
|
5
|
|
vbYes
|
6
|
|
vbNo
|
7
|
Sub
humor()
Do
If
MsgBox(
"Do
you like the Excel-Pratique site ?"
, vbYesNo,
"Survey"
) = vbYes
Then
Exit
Do
'
=> Yes response = Yes we exit the loop
End
If
Loop
While
1 = 1
'
=> Infinite loop
MsgBox
";-)"
End
Sub
MsgBox
"Example
1"
& Chr(10) &
"Example
2"
& Chr(10) & Chr(10)
&
"Example
3"
Sub
example()
Dim
result
As
String
result = InputBox(
"Text ?"
,
"Title"
)
'The
variable is assigned the value entered in the InputBox
If
result <>
""
Then
'If
the value anything but "" the result is displayed
MsgBox result
End
If
End
Sub
InputBox(
"Text
?"
,
"Title"
,
"Default
value"
)