本文介绍了为什么vbCrLf不会创建换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是创建一个简单的VBA脚本来回复带有预定义文本的消息,如下所示:

I am just create a simple VBA script to reply a message with predefined texts, as follows:

Sub AutoReply()

Sub AutoReply ()

    Dim olSelMail As MailItem

    Dim olSelMail As MailItem

    Dim olReply As MailItem

    Dim olReply As MailItem

   

   

   设置olSelMail = Application.ActiveExplorer.Selection.Item(1)

    Set olSelMail = Application.ActiveExplorer.Selection.Item(1)

   设置olReply = olSelMail.Reply

    Set olReply = olSelMail.Reply

   

   

    olReply.HTMLBody ="亲爱的先生/女士" &安培; vbCrLf& _

    olReply.HTMLBody = "Dear Sir/Madam" & vbCrLf & _

                         [确定。感谢和QUOT; &安培; vbCrLf& _

                        "OK. Thanks" & vbCrLf & _

                         "阿兰" &安培; vbCrLf& olReply.HTMLBody

                        "Alan" & vbCrLf & olReply.HTMLBody

    olReply.Display

    olReply.Display

   

   

End Sub

我希望回复会是这样的:

I expect the reply will like this:

尊敬的先生/女士

 

好的。谢谢

 

Alan

....(原文)

但实际上结果是:

亲爱的先生/女士 好。感谢   Alan

...(原文)

似乎vbCrLf根本不起作用。

It seems that the vbCrLf does not work at all.

为什么?

谢谢

推荐答案

您需要在HTML字符串的开头插入回复(将其粘贴到邮件正文中),而不是使用您自己的文本/回复替换原始内容。要完成工作,您需要找到< body>标记并在其后插入您的文字
。例如:

Instead of replacing the original content with your own text/reply you need to insert the reply in the beginning of the HTML string (paste it into the message body). To get the job done you need to find the <body> tag and insert your text right after it. For example:

strLink = "http://msn.com"
strLinkText = "Get Outlook code samples here"
strNewText = "<body><p><a href=" & Chr(34) & strLink & _
             Chr(34) & ">" & strLinkText & "</a></p>"
objMsg.HTMLBody = Replace(objMsg.HTMLBody, "<body>", _
                          strNewText, 1, 1, vbTextCompare)


这篇关于为什么vbCrLf不会创建换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 05:52