【发布时间】:2020-06-27 17:02:51
【问题描述】:
我在 Outlook 的这个 Outlook 会话中有以下 vba 编码。
基本上,此编码会为我组织外部的所有外发电子邮件弹出一个是/否消息框。
编码工作文件,但是,这个outlooksession有时无法识别其中有编码。
但是,当我打开编码窗口 (Alt + F11) 并在标题中放置一个中断并运行编码时,之后它开始正常工作。
我有双重/三重检查,编码没有问题。这与设置有关。
我也启用了所有宏。
关于为什么会发生这种情况以及如何克服这种情况的任何建议或想法?
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
On Error Resume Next
If Item.Class <> olMail Then Exit Sub
Dim sCompanyDomain As String: sCompanyDomain = "tell.com"
Const PidTagSmtpAddress As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
On Error Resume Next
Dim oMail As MailItem: Set oMail = Item
Dim oRecipients As Recipients: Set oRecipients = oMail.Recipients
Dim bDisplayMsgBox As Boolean: bDisplayMsgBox = False
Dim sExternalAddresses As String
Dim oRecipient As Recipient
For Each oRecipient In oRecipients
Dim oProperties As PropertyAccessor: Set oProperties = oRecipient.PropertyAccessor
Dim smtpAddress As String: smtpAddress = oProperties.GetProperty(PidTagSmtpAddress)
Debug.Print smtpAddress
If (Len(smtpAddress) >= Len(sCompanyDomain)) Then
If (Right(LCase(smtpAddress), Len(sCompanyDomain)) <> sCompanyDomain) Then
' external address found
If (sExternalAddresses = "") Then
sExternalAddresses = smtpAddress
Else
sExternalAddresses = sExternalAddresses & ", " & smtpAddress
End If
bDisplayMsgBox = True
End If
End If
Next
If (bDisplayMsgBox) Then
Dim iAnswer As Integer
iAnswer = MsgBox("You are about to send this email externally to " & sExternalAddresses & vbCr & vbCr & "Do you want to continue?", vbExclamation + vbYesNo + vbDefaultButton2, "External Email Check")
If (iAnswer = vbNo) Then
Cancel = True
End If
End If
End Sub
【问题讨论】:
-
“thisoutlooksession 有时无法识别其中包含编码”——这是什么意思?
-
有时编码不能正常工作。
-
您是如何订阅 ItemSend 事件的?查看类似的论坛主题 - stackoverflow.com/questions/28673582/…
-
Eugene,我用 Private Sub Application_Itemsend 开头..
-
不管有没有影响,都是编码有问题。删除 On Error Resume Next 语句,看看会发生什么。除非有原因,否则不要将它们放回去,并尽可能紧跟 On Error GoTo 0。
标签: vba outlook outlook-2010