5

我插入代码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
4

3 回答 3

3

在项目的主题字段上使用和 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
于 2010-04-06T23:28:03.523 回答
2

如果您要挂钩该ItemSend事件,那应该在一个类模块中,WithEvents并且您的代码可以在常规模块中调用它。此外,您还需要Item.Save对密件抄送的消息进行处理。

于 2010-03-26T16:27:37.227 回答
0

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

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

首先,我摆弄了宏观安全性。我将它设置为最低设置。这是一个包含如何更改宏安全性的链接。转到工具 > 宏 > 安全性。我将其设置为“不对宏进行安全检查”。

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

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 并单击了创建。编辑添加了一个名为Modulesunder的部分ThisOutLookSession

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

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

于 2013-11-11T22:23:38.580 回答