Outlook 中可写的主动内联响应

Writeable active inline response in outlook

我从一些博客中获得了以下代码,这些代码将 HTML 从剪贴板插入到 Outlook 电子邮件中。

Sub PrependClipboardHTML()
Dim email As Outlook.MailItem
Dim cBoard As DataObject

Set email = Application.ActiveInspector.CurrentItem
Set cBoard = New DataObject


cBoard.GetFromClipboard
email.HTMLBody = cBoard.GetText + email.HTMLBody

Set cBoard = Nothing
Set email = Nothing

End Sub

它工作得很好,除了电子邮件有自己的 window(即弹出),否则它将失败。

我在查阅文档时发现 Application.ActiveExplorer.ActiveInlineResponse here

但是文档说它是只读的,实际上它不起作用。有没有办法获得内联响应的可写版本?

It works great except that the email has be in its own window (i.e. popped-out) otherwise it will fail.

那是因为你在代码中有如下语句:

Set email = Application.ActiveInspector.CurrentItem

However the documentations says that it is read-only, and indeed it does not work.

尝试改用以下代码:

Set email = Application.ActiveExplorer.ActiveInlineResponse

ActiveInlineResponse 属性 是只读的,但不是您将要使用的对象的属性。这意味着您不能将另一个邮件项目设置为内联响应,但可以设置检索到的项目的属性。

您不能连接两个 HTML 字符串并期望返回有效的 HTML。两者必须合并。

也就是说,使用 Word 对象模型从剪贴板粘贴:

Application.ActiveEXplorer.ActiveInlineResponseWordEditor.Application.Selection.Paste() 

也许您正在尝试使用 ActiveExplorer + Selection.Item Method (Outlook)

示例

Option Explicit
Public Sub Example()    
    Dim email  As Outlook.MailItem
    Set email = Application.ActiveExplorer.Selection.Item(1)
        Debug.Print email.Subject ' print on immediate window    
End Sub

Or Work with both opened and selected items

Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application

    Set objApp = Application

    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select

    Set objApp = Nothing
End Function