如何添加条件以检查主题行是否不包含某些文本以及收件人是否在组织外部?

时间:2019-04-05 17:46:34

标签: vba outlook outlook-vba

以下代码在发送电子邮件之前强制提示进行确认。

我想添加一个条件,即仅在主题行中不包含“ encrypt”一词并且收件人位于组织外部时,才出现提示。

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim xPrompt As String
Dim xOkOrCancel As Integer
On Error Resume Next
xPrompt = "Do you want to continue sending the email?"
xOkOrCancel = MsgBox(xPrompt, vbOKCancel)
If xOkOrCancel <> vbOK Then
    Cancel = True
End If
End Sub

1 个答案:

答案 0 :(得分:0)

您可以在vba中将InStr()函数用于Outlook,例如:

With Application.ActiveInspector.CurrentItem 'change this
    If Not InStr(.Subject, "PO") AND right(.senderemailaddres,7) = "@123.com" Then 'do something
End With