Outlook 2007 中的 ItemSend 事件中的密件抄送不再起作用

发布于 2024-08-26 07:02:09 字数 1179 浏览 5 评论 0原文

我在 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 = "[email protected]"

    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

I inserted code in ItemSend and saved the ThisOutlookSession module. It worked once and no longer works. It was saved as VBAproject.OTM and is still there when I open the module after restarting 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 = "[email protected]"

    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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鯉魚旗 2024-09-02 07:02:09

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

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

If Item.Subject = "exact match" Then

    strBcc = "[email protected]"

    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

use and if statement on the Item's Subject field

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

If Item.Subject = "exact match" Then

    strBcc = "[email protected]"

    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

or use if you want a contains a word in the subject

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


End If
对风讲故事 2024-09-02 07:02:09

如果您要挂钩 ItemSend 事件,则该事件应该位于具有 WithEvents 的类模块中,并且您的代码应在常规模块中调用它。此外,您还需要对邮件执行 Item.Save 以便保留密件抄送。

If you're hooking the ItemSend event, that should be in a class module with WithEvents and your code to call it in a regular module. Also, you'll want to do an Item.Save on the message for the BCC to stick.

贱人配狗天长地久 2024-09-02 07:02:09

我最近遇到这个问题。它是在 .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 并单击“创建”。编辑器在 ThisOutLookSession 下添加了一个名为 Modules 的部分。

然后我重新启动 Outlook 并测试了两次,它成功了。

我不太确定我做了什么使它再次开始工作,但这与步骤不太相关,所以希望这可以帮助您和其他遇到同样问题的人。

I was having this issue recently. It started after the .pst file was corrupted in some way and I had to run scanpst.exe (which I had to search my drive for because the error message does not tell you where it is)

After running scanpst.exe and the issue presented itself, this is how I fixed it.

First, I fiddled with macro security. I set it to the lowest setting. Here is a link that covers how to change macro security. Go to Tools > Macro > Security. I set it to "No security check for Macros."

Then I used this exact code:

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

Then I clicked the save button then little green play button to run the macro. It asked me for a Macro name. I used bccUsername and clicked create. The editor added a section called Modules under ThisOutLookSession.

I then restarted Outlook and tested twice and it worked.

I'm not exactly sure what I did that made it start working again, but this is not too involved with the steps so hopefully this helps you and others with the same problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文