如何在VBA中将html连接为字符串?
我是VBA和html的新手,我感到非常困惑 我试图将一个字符串变量设置为等于几个串联的html字符串和控件值。我不知道我做错了什么 这是我的密码:如何在VBA中将html连接为字符串?,html,string,vba,concatenation,quotes,Html,String,Vba,Concatenation,Quotes,我是VBA和html的新手,我感到非常困惑 我试图将一个字符串变量设置为等于几个串联的html字符串和控件值。我不知道我做错了什么 这是我的密码: htmlText = "<HTML><BODY bgcolor=#0b3767> <img height=""71"" width=""500"" alt=""Central Analysis Bureau, Inc. - Know Your Insureds"" src=""http://cabfinancia
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=“”_
& "" _
&txtHtml.Value&“”_
& ""
htmlText是一个字符串。txtLink、txtVolume、txEdition、txtHtml都是表单上的文本框控件。htmlText=“”\ux&=“ux&txtHtml.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>"
行延续语法要求在下划线前加空格。尝试在第一行末尾添加空格:
src=""http://cabfinancial.com/images/logoEmail.png"">"_
变为
src=""http://cabfinancial.com/images/logoEmail.png"">" _
我在bgcolor参数周围添加了双引号,在第一行连续字符之前添加了空格,在“字符串”周围添加了双引号和符号_ &txtHtml.Value&“”_ & ""
你想达到什么目的?什么让你困惑?那么你到底遇到了什么问题?我看到你的代码唯一明显的问题是在第一行末尾的下划线前没有空格。@JohnFx你对双引号的看法完全正确。我从来不知道。有两件事:1)我应该这样做我在发帖前已经测试过代码,2)当它完全错误时,我是如何得到+3的?不管怎样,我删除了我的帖子以避免混淆和错误信息。不用担心。我也不得不收回我的答案。我个人讨厌嵌入引号的语法,但它确实有效。=)非常感谢!我刚刚意识到这一点这是我犯的错误,正要回答我自己的问题……但你比我快了=^)注意,允许的行连续字符数有限制,但是,你可以用src=src&“下一位”重新开始计数“约翰。。。你能用单引号代替双引号吗?这将使它更具可读性,对于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>"