VBA Constants

VBA Constants

Ratings: 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading…

Intrinsic Constants

VBA includes a number of built-in or intrinsic constants whose values are predefined by VBA. The best place to find information about the available intrinsic constants is in the VB object browser or by pressing F2.

Button

ConstantValueDescription
vbOKOnly0Display OK button only.
vbOKCancel1Display OK and Cancel buttons.
vbAbortRetryIgnore2Display Abort, Retry, and Ignore buttons.
vbYesNoCancel3Display Yes, No, and Cancel buttons.
vbYesNo4Display Yes and No buttons.
vbRetryCancel5Display Retry and Cancel buttons.
vbCritical16Display Critical Message icon.
vbQuestion32Display Warning Query icon.
vbExclamation48Display Warning Message icon.
vbInformation64Display Information Message icon.

Return Value

ConstantValueDescription
vbOk1vbOk
vbCancel2vbCancel
vbAbort3vbAbort
vbRetry4vbRetry
vbIgnore5vbIgnore
vbYes6vbYes
vbNo7vbNo
Sub test()
    Dim yesANDno As Integer
    yesANDno = MsgBox("Hello World, are you good?", vbYesNo) 'Display YES or NO button
    If yesANDno = vbYes Then
        Debug.Print "Your answer is: " & vbCrLf & "YES or " & yesANDno 'result return value of 6
    Else
        Debug.Print "Your answer is:" & vbCrLf & "NO or " & yesANDno  'result return value of 7
    End If
End Sub

OUTPUT

 

Your answer is:NO or 7

Your answer is: YES or 6