【问题标题】:Copy word doc body to outlook email: RTE 5将 word 文档正文复制到 Outlook 电子邮件:RTE 5
【发布时间】: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

标签: excel vba outlook ms-word


【解决方案1】:

如果你是后期绑定,那么添加:

Const olFormatRichText As Long = 3

(好像你也没有Option Explicit...)

你可以找到olFormatRichTexthere的合适值。

【讨论】:

  • 我认为 olFormatRichText 是 3 的代名词。啊,是的,Option Explicit... 新的工作机器,还没有重新启用该设置。那会发现这个错误吗?
  • 是的,它会将其标记为未声明。
  • 很不高兴发现 GIF 似乎不起作用。它在Display 中有效,但在发送后它是静止图像。与这个问题无关 - 当我可以相当快地附上它时,不确定是否值得努力让它工作。
  • 我错过了关于 GIF 的要点。是的,我觉得答案可能在 SO 或在线其他地方的某个地方。
猜你喜欢
  • 2019-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-29
  • 2015-01-29
  • 2016-02-05
  • 1970-01-01
  • 2016-02-27
相关资源
最近更新 更多