如何在 VBA 中将 html 连接为字符串?
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
行延续语法需要在下划线之前有一个空格。尝试在第一行末尾添加一个空格:
becomes
The line continuation syntax requires a space before the underscore. Try adding a space at the end of the first line:
becomes
我在您的 bgcolor 参数周围添加了双引号,在您的第一行继续字符之前添加了一个空格,在您的 周围添加了双引号和&符号
顺便说一句:感谢使用&符号进行串联。有些人使用 + ,它有效,但令人困惑。
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.