簡體   English   中英

如何在VBA中將html連接為字符串?

[英]How do I concatenate html as a string in VBA?

我是VBA和html的新手,我感到非常困惑。

我試圖將一個字符串變量設置為等於幾個串聯的html字符串和控制值。 我不知道我在做什么錯。

這是我的代碼:

    htmlText = "<HTML><BODY bgcolor=#0b3767> <img height=""71"" width=""500"" alt=""Central Analysis Bureau, Inc. - Know Your Insureds"" src=""http://cabfinancial.com/images/logoEmail.png"">"_
      & "<a href=" & txtLink.Value & ">Volume " & txtVolume.Value & " Edition " & txtEdition.Value _
      & "</a>" _
      & txtHtml.Value & "<a href=""txtLink.Value"">Click here to read the complete article</a>" _
      & "</BODY></HTML>" 

htmlText是一個字符串。 txtLink,txtVolume,txtEdition,txtHtml都是表單上的文本框控件。

行繼續語法在下划線之前需要一個空格。 嘗試在第一行的末尾添加一個空格:

src=""http://cabfinancial.com/images/logoEmail.png"">"_

src=""http://cabfinancial.com/images/logoEmail.png"">" _
 htmlText = "<HTML><BODY bgcolor='#0b3767'> <img height='71' width='500' alt='Central Analysis Bureau, Inc. - Know Your Insureds' src='http://cabfinancial.com/images/logoEmail.png'>" _ & "<a href='" & txtLink.Value & "'>Volume " & txtVolume.Value & " Edition " & txtEdition.Value _ & "</a>" _ & txtHtml.Value & "<a href='" & txtLink.Value & "'>Click here to read the complete article</a>" _  & "</BODY></HTML>"

我在您的bgcolor參數周圍添加了雙引號,在您的第一行繼續符之前添加了空格,在<a href=txtLink.Value>周圍添加了雙引號和&符

順便說一句:對於使用&符號進行串聯表示贊譽。 某些人使用+起作用,但令人困惑。

htmlText = "<HTML><BODY bgcolor=""#0b3767""><img height=""71"" width=""500"" alt=""Central Analysis Bureau, Inc. - Know Your Insureds"" src=""http://cabfinancial.com/images/logoEmail.png"">" _
  & "<a href=" & txtLink.Value & ">Volume " & txtVolume.Value & " Edition " & txtEdition.Value _
  & "</a>" _
  & txtHtml.Value & "<a href=""" & txtLink.Value & """>Click here to read the complete article</a>" _
  & "</BODY></HTML>"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM