Show AllShow All

DoAlert Method

Displays an alert and returns a Long that indicates which button the user pressed. You can choose to display this alert either through the Microsoft Office Assistant or as a normal message box.

expression.DoAlert(bstrAlertTitle, bstrAlertText, alb, alc, ald, alq, varfSysAlert)

expression    Required. An expression that returns one of the objects in the Applies To list.

bstrAlertTitle Required String. Sets the title of the alert.

bstrAlertText   Required String. Sets the text of the alert.

alb   Required MsoAlertButtonType. Determines which buttons are displayed on the alert.

alc   Required MsoAlertIconType. Determines the icon that is displayed on the alert.

ald   Required MsoAlertDefaultType. Determines which button is set as the default button of the alert. If this argument is set to a value greater than the number of buttons, an error is returned.

alq   Required MsoAlertCancelType. Always set this to msoAlertCancelDefault. Any other setting may return an error.

varfSysAlert   Required Boolean. True if the alert is displayed in a message box or False if the alert is displayed through the Office Assistant.

Remarks

The return values of the DoAlert method corresponds to the values of the vbMsgBoxResult enumerated type (for example, vbYes, vbNo, or vbCancel). In addition to these values, the following values may also be returned:

Example

The following example displays an alert through the Office Assistant and displays a message box indicating which button the user pressed. If the assistant is disabled, the alert is displayed in a normal message box.

Sub AssistantAlert()
    With Application.Assistant
        Select Case _
            .DoAlert( _
            "Test", _
            "Click a button.", _
            msoAlertButtonYesAllNoCancel, _
            msoAlertIconCritical, _
            msoAlertDefaultSecond, _
            msoAlertCancelFirst, _
            False)

            Case vbYes: MsgBox "The user clicked Yes."
            Case vbNo: MsgBox "The user clicked No."
            Case vbCancel: MsgBox "The user clicked Cancel."
            Case 8: MsgBox "The user clicked Yes To All" 'This is the return value for YesToAll
            Case Else
        End Select
    End With
End Sub