1

我有一些 Outlook VBA 代码可以创建 Word 文档并粘贴用户之前选择的电子邮件部分,例如(删除了一些不相关的代码部分)

Private Sub CreateDoc(M As MailItem)
Dim WApp As Word.Application, WDoc As Word.Document, I As Inspector

    Set I = M.GetInspector

    Set WApp = New Word.Application
    WApp.Visible = True
    Set WDoc = WApp.Documents.Add

    Select Case I.EditorType
    Case olEditorWord
        ' this works like a charm, even if multiple parts selected in MailItem
        I.WordEditor.Application.Selection.Copy
        WApp.Selection.PasteAndFormat wdFormatOriginalFormatting

    Case olEditorHTML
        ' trouble starts here ... I don't get it ... best I came up with is
        WApp.Selection.InsertAfter I.HTMLEditor.Selection.CreateRange.Text

    Case Else
        ' unsupported formats
    End Select

    ' clean up
    Set I = Nothing
    Set WDoc = Nothing
    Set WApp = Nothing
End Sub

适用于 Outlook 2003 和 2010

问题:

我的问题在于olEditorHTML我无法弄清楚如何获取包括格式在内的选定文本。到目前为止,我能想到的最好的方法是插入纯文本。谁能帮我找到正确的代码,将 HTMLEditor 中的选定文本导入 Word,包括格式(就像您手动执行 select/Ctrl-C/Ctrl-V 一样)。

4

1 回答 1

2

感谢您对这篇文章。你的问题实际上成了我的一个解决方案[解决一个非常棘手的问题]。

下面的行对我有用,也许它也对你有用[如果你还在寻找解决方案:)

Change the I.WordEditor.Application.Selection.Copy to I.WordEditor.Selection.Copy and it may work.

于 2013-04-10T07:52:26.100 回答