我一直在使用 Office 365 Outlook 帐户。现在,我配置了 3 个电子邮件帐户。因为我创建了 VBA 宏脚本。我不希望这个脚本在我所有的电子邮件帐户中都运行。我只想在指定的帐户中运行 VBA 脚本。如何实现呢?
例如:假设我的三个帐户
-
test@test.com,
-
test1@test.com,
-
test2@test.com。
我只想在以下位置执行我的 VBA 代码
-
test@test.com,
-
test1@test.com,
在以下位置未运行 VBA 脚本
- test2@test.com
我的代码:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim recips As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim pa As Outlook.PropertyAccessor
Dim prompt As String
Dim strMsg As String
Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set recips = Item.Recipients
For Each recip In recips
Set pa = recip.PropertyAccessor
If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@newsdozens.com") = 0 Then
If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@newsdozens2.com") = 0 Then
If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@bnewstest.com") = 0 Then
strMsg = strMsg & " " & pa.GetProperty(PR_SMTP_ADDRESS) & vbNewLine
End If
End If
End If
Next
If strMsg <> "" Then
prompt = "This email will be sent outside of newsdozens.com to:" & vbNewLine & strMsg & "Do you want to proceed?"
If MsgBox(prompt, vbYesNo + vbExclamation + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
End If
End If
End Sub
3 回答
要有选择地启动宏,可以执行以下操作:
有多种获取发件人信息的方法。这应该适用于 EX 或 SMTP 地址。
如果不需要为特定帐户运行 VBA 宏,则可以在
ItemSend
事件中检出发件人的电子邮件地址,并取消其他任何操作: