【问题标题】:Excel VBA in Outlook Appointment - Replace function strips formattingOutlook约会中的Excel VBA - 替换功能条格式
【发布时间】:2016-06-23 15:29:32
【问题描述】:

我正在尝试编写一个宏,使用 .oft appointment 模板将占位符从 Excel 发送到 Outlook 日历。

当使用这样的替换功能时:

Dim oMail as Object
Set myOlApp = CreateObject("Outlook.Application")

Set oMail = myOlApp.CreateItemFromTemplate(path)

(...)

strFind = "Value"
strNew = Cells(x ,y)
oMail.body = Replace (oMail.body, strFind, strNew)

约会以纯文本形式出现,所有格式都被剥离。字体、链接甚至签名。

如果我将值 .body 更改为 .HTMLbody,则替换功能不起作用,模板未经编辑。我不想将电子邮件内容作为正文放入代码中,因为它们有时会发生变化,这会让我每次都编辑宏而不是模板。

有什么建议吗? 我没有主意了。

【问题讨论】:

  • 先将所有内容复制到一个空的word文档中,然后在word文档中进行替换。完成后,您可以将内容复制到 Outlook。
  • 这是一个很好的解决方法,谢谢。但是,我宁愿解决这个问题,因为我似乎定义了一些错误,而不是直接解决问题。如果没有其他解决方案,我会使用它。
  • 如果您有任何发现,请告诉我。我也会有兴趣的。我之前多次看到这个问题(以其他形式),每次解决方案都是使用 MS Word。如果你能找到新的东西,我会非常惊讶和感兴趣。
  • @Ralph 我明天会尝试下面的 RTFBody 东西,但到目前为止,我只是通过简单地拆分它来使用 Word。首先我在电子邮件中做正文,然后设置所有约会详细信息,然后手动将内容从电子邮件复制到约会。它比 Word 更快、更方便,因为它不需要打开另一个程序。手动步骤也有助于数据验证。

标签: vba excel outlook macros


【解决方案1】:

oMail 的 body 属性是纯文本。 RTFbody 具有所有格式,但它是一个字节数组

Dim oMail as Outlook.AppointmentItem
Set myOlApp = CreateObject("Outlook.Application")

Set oMail = myOlApp.CreateItemFromTemplate(path)

 Dim RegulareString As String

'convert from byte array to a string
 RegulareString = StrConv(pushAppt.RTFBody, vbUnicode)

'do your replacements
RegulareString = Replace(RegulareString , strFind, strNew)

'convert back to byte array
Dim theBytes() As Byte
theBytes = StrConv(RegulareString , vbFromUnicode)

oMail.RTFBody = theBytes
oMail.Display

【讨论】:

  • 您好!谢谢你,我明天去看看!
猜你喜欢
  • 2015-11-26
  • 2015-10-22
  • 1970-01-01
  • 2023-02-14
  • 1970-01-01
  • 2013-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多