Using Message Box (MsgBox) in Excel VBA

MsgBox function in VBA displays a message in a window and waits for click on a button.

Example of using Yes-No Message Box:

 
Sub MessageBoxExample()
    Dim iRet As Integer
    Dim strPrompt As String
    Dim strTitle As String
 
    ' Promt
    strPrompt = "Ask Your Question Here, OK?"
 
    ' Dialog's Title
    strTitle = "My Tite"
 
    'Display MessageBox
    iRet = MsgBox(strPrompt, vbYesNo, strTitle)
 
    ' Check pressed button
    If iRet = vbNo Then
        MsgBox "NO!"
    Else
        MsgBox "Yes!"
    End If
End Sub

你可能感兴趣的:(Using Message Box (MsgBox) in Excel VBA)