
我在VBA中有下面的代码,其中包括newline (vbnewline / vbcrlf)。然后在.htmlbody中调用变量"Clientname“。但是,它将整个字符串放在一行中,消除了换行符。
'Variable "un" will be assigned a value using a "For loop" above this code
Reading Text file:
Set oFS = oFSO.OpenTextFile("c:\test.txt")
TxtPro = oFS.ReadAll
If Not (InStr(ClientName, un)) > 0 Then
ClientName = ClientName & vbNewLine & un
End If
with objmail
.bodyformat = olformatHTML
.htmlbody = "<HTML><BODY> " & clientname & _
"<Br> Your File is given below <br> " & txtpro & "</body></html>"
end with发布于 2016-08-19 16:37:50
HTML不像VBA那样理解/解析行提要。对HTML使用<BR>标记。
将该行ClientName = ClientName & vbNewLine & un更改为ClientName = ClientName & "<BR>" & un
根据您的更新问题编辑:
Sub test()
Dim oFSO As New Scripting.FileSystemObject
Dim oFS As Object
Dim txtPro As String
Dim strHTML As String
Dim clientName As String
Set oFS = oFSO.OpenTextFile("C:\temp\test.txt")
txtPro = oFS.ReadAll()
'/ This will replace linefeeds with <BR> to render line breaks in HTML
txtPro = Replace(txtPro, vbCrLf, "<BR>")
strHTML = "<HTML><BODY> " & clientName & _
"<Br> Your File is given below <br> " & txtPro & "</body></html>"
End Subhttps://stackoverflow.com/questions/39043924
复制相似问题