suppose you want to have a message box like below:

here is the code:
Sub msgboxyesno()
Dim answer As String
answer = MsgBox("Do you wish to continue ?", vbYesNo, "Please Answer")
If answer = vbYes Then
'if he or she selects yes below action will be happen
MsgBox " You selected yes"
ElseIf answer = vbNo Then
'if he or she selects no below action will be happen
MsgBox "You selected No"
End If
End Sub
suppose you want to have a message box like below:

code:
Sub msgboxokcancel()
Dim answer As String
answer = MsgBox("Do you wish to continue ?", vbOKCancel, "Please Answer")
If answer = vbOK Then
'if he or she selects vbok below action will be happen
MsgBox "Have a beautiful day... "
ElseIf answer = vbCancel Then
'if he or she selects vbcancel below action will be happen
Exit Sub
End If
End Sub
and if you want to have one like below

code:
Sub msgboxyesnocancel()
Dim answer As String
answer = MsgBox("Do you wish to continue ?", vbYesNoCancel, "Please Answer")
If answer = vbYes Then
MsgBox "Have a beautiful day... "
ElseIf answer = vbNo Then
MsgBox "You selected No"
ElseIf answer = vbCancel Then
Exit Sub
End If
End Sub

here is the code:
Sub msgboxyesno()
Dim answer As String
answer = MsgBox("Do you wish to continue ?", vbYesNo, "Please Answer")
If answer = vbYes Then
'if he or she selects yes below action will be happen
MsgBox " You selected yes"
ElseIf answer = vbNo Then
'if he or she selects no below action will be happen
MsgBox "You selected No"
End If
End Sub
suppose you want to have a message box like below:

code:
Sub msgboxokcancel()
Dim answer As String
answer = MsgBox("Do you wish to continue ?", vbOKCancel, "Please Answer")
If answer = vbOK Then
'if he or she selects vbok below action will be happen
MsgBox "Have a beautiful day... "
ElseIf answer = vbCancel Then
'if he or she selects vbcancel below action will be happen
Exit Sub
End If
End Sub
and if you want to have one like below

code:
Sub msgboxyesnocancel()
Dim answer As String
answer = MsgBox("Do you wish to continue ?", vbYesNoCancel, "Please Answer")
If answer = vbYes Then
MsgBox "Have a beautiful day... "
ElseIf answer = vbNo Then
MsgBox "You selected No"
ElseIf answer = vbCancel Then
Exit Sub
End If
End Sub
No comments:
Post a Comment