0

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.

2
  • What are you trying to achieve? What is getting you confused? Commented Dec 15, 2009 at 15:49
  • So what is the problem you are experiencing exactly? The only obvious problem I see with your code is that you don't have a space before the underscore at the end of the first line. Commented Dec 15, 2009 at 15:53

3 Answers 3

2

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"">" _
Sign up to request clarification or add additional context in comments.

6 Comments

@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.
No worries. I've had to retract my share of answers too. Personally I hate that syntax for embedding quotes, but it does work. =)
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 =^)
Note that there is a limit on the number of line continuations characters that you are allowed, however, you can restart the count with src=src & "next bit"
John... can you also replace the double-double quotes with single quotes? This should make it more readable and should be fine for HTML.
|
0
 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>"

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.