大家好,我遇到了将单词内容复制到所选回复电子邮件的问题。这是我的代码。
Sub ReplyMail_No_Movements_original()
' Outlook's constant
Dim oItem As Outlook.MailItem
Const olFolderSentMail = 5
Const olMail = 43
' Variables
Dim OutlookApp As Object
Dim IsOutlookCreated As Boolean
Dim sFilter As String, sSubject As String
' Get/create outlook object
On Error Resume Next
Set OutlookApp = GetObject(, "Outlook.Application")
If Err Then
Set OutlookApp = CreateObject("Outlook.Application")
IsOutlookCreated = True
End If
On Error GoTo 0
' Restrict items
sSubject = ActiveCell.Value
sFilter = "[Subject] = '" & sSubject & "'"
' Main
With OutlookApp.Session.GetDefaultFolder(olFolderSentMail).Items.Restrict(sFilter)
If .Count > 0 Then
.Sort "ReceivedTime", True
With .item(1).ReplyAll
.HTMLBody = Cells(ActiveCell.Row, "F") & "<br><br>" & word_rng(oItem) & "<br>" & .HTMLBody '<==Problem part of word_rng(oItem)
.Display
.Save
'.Send
If Cells(ActiveCell.Row, "H").Text <> "" Then
.Attachments.Add (Cells(ActiveCell.Row, "H").Text)
End If
If Cells(ActiveCell.Row, "I").Text <> "" Then
.Attachments.Add (Cells(ActiveCell.Row, "I").Text)
End If
SendKeys "^+{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{END}", True
wd.Close False
Set wd = Nothing
End With
Else
MsgBox "No emails found with Subject:" & vbLf & "'" & sSubject & "'"
End If
End With
' Quit Outlook instance if it was created by this code
If IsOutlookCreated Then
OutlookApp.Quit
Set OutlookApp = Nothing
End If
End Sub
Private Function word_rng(oItem As Outlook.MailItem) As Object
'On Error Resume Next
Dim WordFile As String
WordFile = Cells(1, 3).Value
Dim wd As Object, editor As Object
Set wd = GetObject(WordFile)
wd.Content.Copy
Set editor = oItem.GetInspector.WordEditor
editor.Content.Paste
'On Error GoTo 0
End Function
我想将word文件内容复制到此回复电子邮件中并保留旧消息。
看起来像
=================
我想将内容粘贴到电子邮件正文的中间,但是我用.htmlbody
或.body
测试了很多次。它仍然无法工作。 (我有签名,所以我需要使用.htmlbody
有人知道如何解决吗?,这真的使我疯狂了近一个星期。 另外,回复电子邮件格式不能保留原始格式。使用vba后,所有文本都将被截断为“蓝色”,并且无法显示签名。一些文本应显示红色或黄色,我之前已对其进行了标记。但这一切都变成了“蓝色”
编辑1:我创建了一个函数来将单词内容的副本放置在.htmlbody中 但出现错误的对象变量或未设置块变量