【发布时间】:2020-07-28 17:27:21
【问题描述】:
我正在尝试将 word doc 的所有内容复制到 Outlook 电子邮件正文中,同时保持格式,并希望遵循在 this 帖子中找到的解决方案,但在以下行中出现错误:.BodyFormat = olFormatRichText .删除错误处理程序后,我得到RTE5: Invalid procedure call or argument
知道为什么这条线会引发错误或如何更正吗?
Sub Sender(Target As Range)
Dim OutApp As Object
Dim OutMail As Object
Dim wd As Object
Dim editor As Object
Dim doc As Object
Dim fp As String
fp = "C:\Users\urdearboy\"
Set wd = CreateObject("Word.Application")
Set doc = wd.documents.Open(fp & "mydearfile.docx")
doc.Content.Copy
doc.Close
Set wd = Nothing
On Error GoTo BNP:
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.SentOnBehalfOfName = "urdearboy@so.com"
.to = Target.Offset(, 2)
.Subject = "Hi Mom"
.BodyFormat = olFormatRichText '<----- ERROR LINE
Set editor = .GetInspector.WordEditor
editor.Content.Paste
.Display
'.Send
Target.Offset(, -1) = "Sent"
End With
BNP:
Set OutApp = Nothing
Set OutMail = Nothing
End Sub
上下文:我决定使用 Word 到 Outlook 的副本,因为该文件有很多格式和照片,并且在 Outlook HTML 中严格获取正确的格式听起来像是一场噩梦。如果手动完成,这将基本上是一个完整的CTRL + A + Copy from word 和CTRL + V 在 Outlook 中,它保持所有格式、照片和 gif 格式正确。这里的目标是在 VBA 中模拟该过程。如果有更好的解决方案,也欢迎那里的想法
【问题讨论】:
-
您是否参考了 Outlook 库集?
-
如果没有,
Const olFormatRichText as Long = 3。