从Microsoft Word到Outlook的选择使用VBA的新电子邮件
问题描述:
我试过这个Microsoft Word宏,将我已经完成的选择粘贴到新电子邮件中,但是当我以HTML格式执行时,虽然在末尾没有<br>
每一段,结果都是一句一句的,没有回车。从Microsoft Word到Outlook的选择使用VBA的新电子邮件
例子:
文本1
文本2
文本3
我得到:
文本1文本2文本3
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Set rng = ActiveDocument.Range(Start:=Selection.Start, End:=Selection.End)
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
On Error Resume Next
With OutMail
.Display
.To = "[email protected]"
.CC = "[email protected]"
.BCC = ""
.Subject = Date
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><body><font face=""calibri"" style=""font-size:11pt;""><br>" & rng & _
"<br><br></body>" & _
"Best Reagrds" & _
.HTMLBody & "</font>"
.Text
答
试试这个在您的代码(未经测试)
dim sen as variant
.HTMLBody = "<HTML><body><font face=""calibri"" style=""font-size:11pt;""><br>"
for each sen in rng.sentences
.htmlbody = .htmlbody & sen & "<br>" ' may have to be sen.text
next sen
....
+0
+0
我也将rng.Sentences更改为rng.Paragraphs更好,而在句子中,有时候用点不要关闭这段时间,而只是稍后作出评论。所以段落要好得多,但仍然缺少签名。 – massimob1972
的一种方式解决这个问题可能会使用文本框。请参阅https://stackoverflow.com/questions/45362791/vba-email-loop-for-excel-reporting/45363726#45363726 –
在Word中这不起作用!它出现了编译错误:Sub或Function没有在Set上定义r =范围(“B1) – massimob1972
右边 - 那个代码是为Excel模块编写的 –