【问题标题】:BCC in ItemSend event in Outlook 2007 no longer worksOutlook 2007 中的 ItemSend 事件中的密件抄送不再有效
【发布时间】:2011-02-01 03:31:56
【问题描述】:

我在ItemSend 中插入了代码并保存了 ThisOutlookSession 模块。它工作了一次,不再工作。它被保存为 VBAproject.OTM 并且在我重新启动 Outlook 后打开模块时仍然存在。

Private Sub Application_ItemSend(ByVal Item As Object, _
                                 Cancel As Boolean)
    Dim objRecip As Recipient
    Dim strMsg As String
    Dim res As Integer
    Dim strBcc As String
    On Error Resume Next

    ''# #### USER OPTIONS ####
    ''# address for Bcc -- must be SMTP address or resolvable
    ''# to a name in the address book
    strBcc = "someone@somewhere.dom"

    Set objRecip = Item.Recipients.Add(strBcc)
    objRecip.Type = olBCC
    If Not objRecip.Resolve Then
        strMsg = "Could not resolve the Bcc recipient. " & _
                 "Do you want still to send the message?"
        res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
                "Could Not Resolve Bcc Recipient")
        If res = vbNo Then
            Cancel = True
        End If
    End If

    Set objRecip = Nothing
End Sub

【问题讨论】:

  • FWIW 电子邮件地址将始终解析,因此无需调用 Resolve 方法或检查其值。

标签: vba email outlook bcc


【解决方案1】:

我最近遇到了这个问题。它是在 .pst 文件以某种方式损坏后开始的,我不得不运行 scanpst.exe(我不得不搜索我的驱动器,因为错误消息没有告诉你它在哪里)

运行 scanpst.exe 并出现问题后,我就是这样修复它的。

首先,我摆弄了宏安全性。我将它设置为最低设置。 Here is a link that covers how to change macro security。转到工具 > 宏 > 安全性。我将其设置为“不对宏进行安全检查”。

然后我使用了这个确切的代码:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim objRecip As Recipient
Dim strMsg As String
Dim res As Integer
Dim strBcc As String
On Error Resume Next

' #### USER OPTIONS ####
' address for Bcc -- must be SMTP address or resolvable
' to a name in the address book
strBcc = "PUT YOUR EMAIL ADDRESS HERE AND LEAVE THE QUOTES"

Set objRecip = Item.Recipients.Add(strBcc)
objRecip.Type = olBCC
If Not objRecip.Resolve Then
strMsg = "Could not resolve the Bcc recipient. " & _
"Do you want still to send the message?"
res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
"Could Not Resolve Bcc Recipient")
If res = vbNo Then
Cancel = True
End If
End If

Set objRecip = Nothing

End Sub

然后我单击保存按钮,然后单击绿色的小播放按钮来运行宏。它问我一个宏名称。我使用了 bccUsername 并单击了创建。编辑在ThisOutLookSession下添加了一个名为Modules的部分。

然后我重新启动 Outlook 并测试了两次,它工作正常。

我不确定我做了什么让它重新开始工作,但这与步骤无关,所以希望这可以帮助你和其他有同样问题的人。

【讨论】:

    【解决方案2】:

    在项目的主题字段上使用和 if 语句

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    
    If Item.Subject = "exact match" Then
    
        strBcc = "someone@somewhere.dom"
    
        Set objRecip = Item.Recipients.Add(strBcc)
        objRecip.Type = olBCC
        If Not objRecip.Resolve Then
            strMsg = "Could not resolve the Bcc recipient. " & _
                     "Do you want still to send the message?"
            res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
                    "Could Not Resolve Bcc Recipient")
            If res = vbNo Then
                Cancel = True
            End If
    
    
        End If
        Item.Save
    
        Set objRecip = Nothing
    
    
    End If
    

    如果你想在主题中包含一个单词,请使用

    If InStr(Item.Subject, "BCCSubject") = 0 Then
    
    
    End If
    

    【讨论】:

      【解决方案3】:

      如果您要挂接ItemSend 事件,则该事件应位于具有WithEvents 的类模块中,并且您的代码应在常规模块中调用它。此外,您需要在消息上添加Item.Save,以便密件抄送。

      【讨论】:

        猜你喜欢
        • 2014-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-27
        • 2018-09-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多