Question

I am running into a situation in which I am using VBA to generate HTML code that will go into an Outlook email. The HTML code has a bunch of images in it and I am storing the image path names in string variables. For Outlook to recognize the image, it needs quotes around it in the format:

<img src="filepath">

The problem is when I write the VBA code to contain the quotation marks, it doesn't realize the variable is a variable and instead inputs it as text. Here is the code I am using (this is just the snippet causing problems:

 StageID = "C:\Users\xxxxx\Desktop\stage1.png"
 Body = Body & "<TR><TD width=""100"" rowspan=""6"" align=""middle""><img src="""" & StageID & """" align=""middle"" width=""100"" height=""200""></td></tr>
Was it helpful?

Solution

You can use single quotes for HTML attribute values:

StageID = "C:\Users\xxxxx\Desktop\stage1.png"

Body = Body & "<TR><TD width='100' rowspan='6' align='middle'>" & _
              "<img src='" & StageID & "' align='middle' width='100' " & _
              " height='200'></td></tr>"

OTHER TIPS

You have one too many inverted commas. try this:

body = body & "<TR><TD width=""100"" rowspan=""6"" align=""middle""><img src=""" & StageID & """ align=""middle"" width=""100"" height=""200""></td></tr>"

3 inverted commas either side of the & for the variable substitution works for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top