如何在 VBA 中将 html 连接为字符串?

发布于 2024-08-15 07:35:34 字数 733 浏览 1 评论 0原文

我是 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 都是表单上的文本框控件。

I'm a newbie at VBA and html and I'm getting very confused.

I'm trying to set a string variable to equal several concatenated html strings and control values. I can't figure out what I'm doing wrong.

Here is my code:

    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 is a String. txtLink, txtVolume, txtEdition, txtHtml are all Textbox Controls on a form.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空袭的梦i 2024-08-22 07:35:34

行延续语法需要在下划线之前有一个空格。尝试在第一行末尾添加一个空格:

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

becomes

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

The line continuation syntax requires a space before the underscore. Try adding a space at the end of the first line:

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

becomes

src=""http://cabfinancial.com/images/logoEmail.png"">" _
岁月静好 2024-08-22 07:35:34
 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 = "<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>"
岁月流歌 2024-08-22 07:35:34

我在您的 bgcolor 参数周围添加了双引号,在您的第一行继续字符之前添加了一个空格,在您的 周围添加了双引号和&符号

顺便说一句:感谢使用&符号进行串联。有些人使用 + ,它有效,但令人困惑。

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>"

I added double quotes around your bgcolor parameter, added a space before your first line continuation character, added double quotes and ampersands around your <a href=txtLink.Value>

BTW: Kudos on using ampersands for concatenation. Some people use + which works, but is confusing.

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>"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文