我想所有的Word文档的内容复制到Outlook电子邮件的身体,同时保持格式并期待遵循找到了解决这一职位,但我得到以下行错误:.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 = "[email protected]"
.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 to Outlook副本,因为该文件具有很多格式和照片,并且严格在Outlook HTML中获得正确的格式听起来像噩梦。如果手动完成,这实际上是CTRL + A + Copy
Word和CTRL + V
Outlook中的完整内容,可以使所有格式,照片和gif格式保持正确格式。这里的目标是模仿VBA中的该过程。如果有更好的解决方案,也应该对此有所开放
如果您后期绑定,请添加:
Const olFormatRichText As Long = 3
(好像您也Option Explicit
没穿……)
您可以在olFormatRichText
此处找到适当的值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句