如果主题包含字符串,如何显示msgbox

时间:2017-08-22 20:12:13

标签: vba outlook outlook-vba outlook-2016

以下Outlook宏工作正常,但是,我希望仅当主题为MsgBox或主题为LIKE 'Fees Due%'时才显示此LIKE' Status Change%'。这可能吗?

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If MsgBox("Do you want to continue sending the mail?", vbOKCancel) <> vbOK Then
        Cancel = True
    End If
End Sub

2 个答案:

答案 0 :(得分:1)

 

是。使用Like运算符:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If Item.Subject Like "Fees Due*" Or Item.Subject Like "Status Change*" Then
        If MsgBox("Do you want to continue sending the mail?", vbOKCancel) <> vbOK Then
            Cancel = True
        End If
    End If
End Sub

我添加了外If ... End If,没有其他内容被更改。

答案 1 :(得分:0)

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim Subject As String
    Subject = Item.Subject

    If Subject Like "*Fees Due*" Or Subject Like "*Status Change*" Then
        If MsgBox("Do you want to continue sending the mail?", _
                   vbYesNo + vbQuestion + vbMsgBoxSetForeground, _
                                               "Check Subject") = vbNo Then
            Cancel = True
        End If

    End If
End Sub