【问题标题】:VBA scripts not running in Outlook 2007VBA 脚本未在 Outlook 2007 中运行
【发布时间】:2014-12-23 21:03:51
【问题描述】:

我在通过 Outlook 2007 发送的每条消息上都放置了一个新的 VBA 脚本,以便我自己自动密件抄送。该代码似乎运行良好。我遇到的问题是,每次我重新启动计算机并加载 Outlook 2007 时,代码才会在我打开 VBA 编辑器之后才使用。即使我关闭编辑器,它也会继续以这种方式正常运行。每次打开 Outlook 2007 时是否必须打开然后关闭 VBA 编辑器?有没有办法在打开和加载 Outlook 2007 时强制 VBA 脚本参与?

这是我正在使用的脚本:

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@domain.com"

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

    Set objRecip = Nothing
End Sub

【问题讨论】:

  • 看来问题来自您的信任中心设置。您需要在 Outlook 中调整宏安全设置。尝试将其设置为最低级别。

标签: vba loading outlook-2007


【解决方案1】:

首先,检查 Outlook 中的宏安全设置。如果它们设置为“无警告并禁用所有宏”(最高安全设置),您仍然可以直接从 VBA IDE 运行代码,但由于禁用了宏,您的代码将无法运行当 VBA IDE 未打开时,从 Outlook 的资源管理器中获取。

如果您的安全设置足够低以允许宏运行,那么下一步就是尝试确定错误发生的位置。首先删除“On Error Resume Next”行(顺便说一句,这是一件可怕的事情),并将其替换为“On Error GoTo ErrTrap”。

然后,编写一个名为ErrTrap() 的子程序来处理错误。您可以使用 Err.NumberErr.Description 对象将有意义的错误消息提供给 MessageBox。在此处发布消息,我们或许可以帮助您从那里进行故障排除。

干杯,

-=卡梅隆

【讨论】:

    猜你喜欢
    • 2010-10-24
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    • 1970-01-01
    • 2012-11-15
    相关资源
    最近更新 更多