我有一些 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 一样)。