【问题标题】:How to fire Outlook's Application_ItemSend when sending mail from an outside, non-Office, program?从外部非 Office 程序发送邮件时如何触发 Outlook 的 Application_ItemSend?
【发布时间】:2021-06-28 09:00:11
【问题描述】:

我希望在发送电子邮件时触发宏。现在它只是一个消息框:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim xText As String
    MsgBox ("hi there")
End Sub

这在使用 Outlook 本身时有效,但在我从外部程序 Nautilus LIMS 发送时无效。

【问题讨论】:

标签: vba outlook


【解决方案1】:

如果您在 Excel 中,请确保您已选中 Microsoft Outlook 16.0 对象库。在 VBA IDE 中转到工具/参考,然后向下滚动到 Microsoft Outlook 16.0 对象库,选中该框并单击确定。此外,请确保 Outlook 程序正在运行。 此代码应在 Excel VBA 模块中工作。

Sub TestEmail()

    Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
               
    On Error Resume Next
    With OutMail
        .BodyFormat = olFormatHTML
        .display
        .To = "knappyflash2@gmail.com"
        .CC = ""
        .BCC = ""
        .Subject = "This is a Test"
        .HTMLBody = "<FONT SIZE = 4><P>Hello,</P><P>This is a test Email</P><P>Thank you</P>" & .HTMLBody
        '.Attachments.Add ActiveWorkbook.FullName
        'You can add other files also like this
        '.Attachments.Add ("C:\test.txt")
        .send   'or use .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
    
End Sub

【讨论】:

  • 嗨。感谢您尝试提供帮助。这是一个使用 Outlook 发送电子邮件的 Nautilus LIMS 程序。不是另一个 Office 程序
猜你喜欢
  • 1970-01-01
  • 2017-01-25
  • 1970-01-01
  • 1970-01-01
  • 2021-06-12
  • 2014-04-04
  • 1970-01-01
  • 1970-01-01
  • 2013-05-27
相关资源
最近更新 更多