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 Analysi开发者_运维问答s 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.
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"">" _
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>"
精彩评论