电子邮件中的新行通过使用换行符创build单元格值的消息:VBA
我正面临与VBA邮件相关的问题。
例如。 在单元格A1中我有:
Test test test test test test
而当我从一个单元格A1生成邮件时,string出现时没有换行符,我的意思是
Test test test test test test.
我试图用"\r\n"
replace为"<br/>"
但是这不起作用。
Content = Replace(Content , "\r\n", "<br/>")
有谁能帮我解决这个问题吗?
关键是用HTML换行符replaceExcel的换行符Chr(10)
电邮地址:
Sub mail() Dim OutApp As Object, OutMail As Object, strbody As String ' Get string from cell, replace Chr(10) (the cell new line) with a html <br> strbody = ThisWorkbook.Sheets("Sheet1").Range("A1").Value strbody = Replace(strbody, Chr(10), "<br>") ' Create email and add string as HTMLBODY item On Error Resume Next Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) With OutMail .to = "" .CC = "" .Subject = "Subject here" .htmlbody = strbody .Display End With On Error GoTo 0 End Sub
输出继电器: