访问VBA Outlook Mailtiem.Body与MailItem.HTMLBody [英] Access VBA Outlook Mailtiem.Body vs MailItem.HTMLBody

查看:456
本文介绍了访问VBA Outlook Mailtiem.Body与MailItem.HTMLBody的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自定义超链接填充一系列生成的电子邮件,但是在使超链接正确生成方面遇到麻烦。
我有一个用户表单,允许创建报告的人在电子邮件正文中输入文本字段。该字段分配给表。

I am Trying to Populate a Series of Generated Emails With Custom Hyperlinks But am Having Trouble in Getting the Hyperlinks to Generate Properly. I Have a User Form that allows the Person Creating the Reports to Enter in the E-Mail Body into a Text Field. This Field is Assigned to a Table.

在我的代码中,我提取这些字段并解析它们以获取DATE和HYPERLINK之类的关键字,并用代码生成的数字替换这些关键字。

In My Code I am Pulling those Fields and Parsing them for Keywords like DATE and HYPERLINK and Replacing those Keywords with the Code Generated Numbers.

当我创建超链接时,我将它们插入如下所示的主体字符串中:

As I Create Hyperlinks I am Inserting them into the Body String like Below:

Function CreateHyperLink(HyperText, HyperLink) As String

    CreateHyperLink = "<HTML><BODY>"
    CreateHyperLink = CreateHyperLink & "<A href='" & HyperLink & "'>'" & HyperText & "'</A>"
    CreateHyperLink = CreateHyperLink & "</BODY></HTML>"

End Function

但是当我插入这些as(eBody是一个数组字符串)

But When I insert these as(eBody is an Array of Strings)

 Set oMail = oApp.CreateItem(olMailItem)
 With oMail
    .To = t
    .CC = c
    .HTMLBody = eBody(i)
    .Subject = eSubject(i)
ETC.....

超链接创建正确,但是我丢失了用户输入文本中的所有间距和换行符。

The Hyperlinks Create Properly But I lose all the Spacing and Line Breaks from the Text the User Entered.

如果相反,我使用

 Set oMail = oApp.CreateItem(olMailItem)
 With oMail
    .To = t
    .CC = c
    .Body = eBody(i)
    .Subject = eSubject(i)
ETC.....

我保留所有格式,但丢失了超链接。
是否有两全其美的解决方案?我不希望我的用户必须以HTML格式输入整个电子邮件。

I Keep all the Formating but Lose the Hyperlink. Is There a Best of Both Worlds Solution? I Do not want my Users to have to Type in the entire Email in HTML.


方法.htmlBody的示例输出(超链接有效,但缺少格式)

Example Output of Method .htmlBody (Hyperlink is Valid but Missing Format)

可以通过以下方式访问文件:
'单击此处访问报告'
请使用过滤器选择您的...

The file can be accessed via: 'Click here to access the Report ' Please use the filters to select your...


.Body方法的示例输出(超链接无效但已格式化)

Example Output of Method .Body (Hyperlink is not Valid but Formated)

可以通过以下方式访问文件:

The file can be accessed via :

<HTML><BODY><A href='http://FILELOCATION'>'Click here to access the Report '</A></BODY></HTML>  " 

请使用过滤器选择您的...

Please use the filters to select your...

是否可以在.body中添加超链接或使用.HTMLbody保持格式?

Is there a Way to add Hyperlinks in .body or a way to Keep Formatting with .HTMLbody?

推荐答案

看看电子邮件正文中间的范围 。我的答案在那里显示了如何插入到现有 .HTMLBody

Have a look at Range in Middle of Email Body. My answer there shows how to insert into the middle of an existing .HTMLBody.

这篇关于访问VBA Outlook Mailtiem.Body与MailItem.HTMLBody的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆