首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HTML NewLine问题

HTML NewLine问题
EN

Stack Overflow用户
提问于 2016-08-19 16:36:01
回答 1查看 795关注 0票数 0

我在VBA中有下面的代码,其中包括newline (vbnewline / vbcrlf)。然后在.htmlbody中调用变量"Clientname“。但是,它将整个字符串放在一行中,消除了换行符。

代码语言:javascript
复制
  '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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-19 16:37:50

HTML不像VBA那样理解/解析行提要。对HTML使用<BR>标记。

将该行ClientName = ClientName & vbNewLine & un更改为ClientName = ClientName & "<BR>" & un

根据您的更新问题编辑:

代码语言:javascript
复制
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 Sub
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39043924

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档