DoAlert Method

Microsoft Office Object Model

Show 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.

MsoAlertButtonType can be one of these MsoAlertButtonType constants.
msoAlertButtonAbortRetryIgnore
msoAlertButtonOK
msoAlertButtonOKCancel
msoAlertButtonRetryCancel
msoAlertButtonYesAllNoCancel Only use this when the varfSysAlert argument is set to False.
msoAlertButtonYesNo
msoAlertButtonYesNoCancel

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

MsoAlertIconType can be one of these MsoAlertIconType constants.
msoAlertIconCritical
msoAlertIconInfo
msoAlertIconNoIcon
msoAlertIconQuery
msoAlertIconWarning

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.

MsoAlertDefaultType can be one of these MsoAlertDefaultType constants.
msoAlertDefaultFifth
msoAlertDefaultFirst
msoAlertDefaultFourth
msoAlertDefaultSecond
msoAlertDefaultThird

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

MsoAlertCancelType can be one of these MsoAlertCancelType constants.
msoAlertCancelDefault
msoAlertCancelFifth
msoAlertCancelFirst
msoAlertCancelFourth
msoAlertCancelSecond
msoAlertCancelThird

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:

  • "Yes to all" = 8
  • "Try again" = 10
  • "Continue" = 11

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