views:

319

answers:

3

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""&gt;"_
      & "<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.

A: 
 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'&gt;" _ & "<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>"
JonH
+2  A: 

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""&gt;"_

becomes

src=""http://cabfinancial.com/images/logoEmail.png""&gt;" _
JohnFx
@JohnFx you were exactly correct about the double quotes. I never knew that. Two things: 1) I should have tested the code before posting and 2) How in the world did I get +3 on that when it was flat wrong? Either way, I deleted my post to avoid confusion and misinformation.
Ben McCormack
No worries. I've had to retract my share of answers too. Personally I hate that syntax for embedding quotes, but it does work. =)
JohnFx
Thank you so much! I just realized that that was the mistake I made and was about to answer my own question...but you beat me to it =^)
dmr
Remou
John... can you also replace the double-double quotes with single quotes? This should make it more readable and should be fine for HTML.
Mark Nold
Definitely. That is a common approach where double and single quotes are interchangeable in the output.
JohnFx
A: 

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""&gt;" _
  & "<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>"
Beaner