我们有一个 Access 数据库,它使用该SendObject
方法将报告导出为电子邮件的附件。
我需要做的是打开附件,复制文本(带格式)并将其粘贴到生成的电子邮件正文中并删除文件。
我有删除附件并打开它的代码,但我不确定如何复制 Word 文档中的所有内容并将其粘贴回原始电子邮件。
任何帮助将不胜感激!如果有更简单的方法,请告诉我。
Sub olAttachmentStrip()
Dim strFilename As String
Dim strPath As String
Dim olItem As Outlook.MailItem
Dim olAtmt As Outlook.Attachments
Dim olInspector As Outlook.Inspector
Dim appWord As Word.Application
Dim docWord As Word.Document
strPath = "C:\temp\"
Set olInspector = Application.ActiveInspector
If Not TypeName(olInspector) = "Nothing" Then
If TypeName(olInspector.CurrentItem) = "MailItem" Then
Set olItem = olInspector.CurrentItem
Set olAtmt = olItem.Attachments
olAtmt.Item(1).SaveAsFile strPath & olAtmt.Item(1).DisplayName
strFilename = strPath & olAtmt.Item(1).DisplayName
'olAtmt.Item(1).Delete
Else
MsgBox "Something went horribly wrong."
End If
End If
Set appWord = CreateObject("Word.Application")
appWord.Visible = False
Set docWord = appWord.Documents.Open(strFilename)
Stop '<== This is where I'm stuck!
Set docWord = Nothing
Set appWord = Nothing
End Sub