HTML using VBA for body of email

jam1531

New Member
Joined
Jan 5, 2015
Messages
29
Hello, I am trying to insert HTML code for the first time in my VBA to help format the body with bold, font, number point, etc.

I found a nifty site (https://www.quackit.com/html/online-html-editor/) that allows me to build what I want the email body to look like and then it gives me the HTML. However, when I put the code into the VBA there are multiple lines and it tries to put quotations around just the first line. If possible, how do I put this code in?

Code below:

Code:
                With OutlookMessage                 .To = "Jesse.McKibben@walmart.com"
                 .CC = ""
                 .BCC = ""
                 .Subject = TempFileName
                 .HTMLBody = "<p><kbd><big><tt>Hello,</tt> </big></kbd><o:p></o:p></p>"


                            <p><kbd><big>Please execute the following for all of the attached items </big></kbd><o:p></o:p></p>
                            
                            <ol>
                                <li><kbd><big>Place item in deleted status</big></kbd></li>
                                <li><kbd><big>Do <strong>NOT</strong> change Item Desc 1 to delete</big></kbd></li>
                                <li><kbd><big>Remove all traits and flags</big></kbd></li>
                                <li><kbd><big>Change Item expiration date to current date</big></kbd></li>
                                <li><kbd><big>After deleted send all items to BPS that have PLU's to have PLU removed </big></kbd><o:p></o:p></li>
                            </ol>
                            
                            <p><kbd><big>Thanks!</big></kbd> <o:p></o:p></p>"
                 .Attachments.Add DestinWB.FullName
                 .Display
                End With

Any help appreciated.
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I feel like a real rookie here. When I pasted in my HTML code it turned into the text I wanted and got rid of the code... Not sure how to paste in the code.
 
Upvote 0
You would build the HTML up line by line, something like this.
HTML:
strHTML = strHTML & "<p style='margin: 0px 0px 1em; padding: 0px; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; background-color: rgb(250, 250, 250);'><kbd style='line-height: 13px;'><big>Please execute the following for all of the attached items</big></kbd><o:p></o:p></p>"
strHTML = strHTML & "<ol style='margin: 0px 40px; padding-right: 0px; padding-left: 0px; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; background-color: rgb(250, 250, 250);'>"
strHTML = strHTML & "<li style='margin: 0px; padding: 0px; list-style: decimal outside;'><kbd style='line-height: 13px;'><big>Place item in deleted status</big></kbd></li>"
strHTML = strHTML & "<br />"
strHTML = strHTML & "<li style='margin: 0px; padding: 0px; list-style: decimal outside;'><kbd style='line-height: 13px;'><big>Do <strong style='font-style: inherit;'>NOT</strong> change Item Desc 1 to delete</big></kbd></li>"
strHTML = strHTML & "<br />"
strHTML = strHTML & "<li style='margin: 0px; padding: 0px; list-style: decimal outside;'><kbd style='line-height: 13px;'><big>Remove all traits and flags</big></kbd></li>"
strHTML = strHTML & "<br />"
strHTML = strHTML & "<li style='margin: 0px; padding: 0px; list-style: decimal outside;'><kbd style='line-height: 13px;'><big>Change Item expiration date to current date</big></kbd></li>"
strHTML = strHTML & "<li style='margin: 0px; padding: 0px; list-style: decimal outside;'><kbd style='line-height: 13px;'><big>After deleted send all items to BPS that have PLU's to have PLU removed</big></kbd><o:p></o:p></li>"
strHTML = strHTML & "<br />"
strHTML = strHTML & "<br />"
strHTML = strHTML & " "
strHTML = strHTML & "</ol>"
strHTML = strHTML & "<p style='margin: 0px 0px 1em; padding: 0px; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; background-color: rgb(250, 250, 250);'><kbd style='line-height: 13px;'><big>Thanks!</big></kbd></p>"
 
Upvote 0
Thanks Norie. I am struggling with implementation of your response.

so should each line say "HTMLBody =" before the line?
 
Last edited:
Upvote 0
No you would use what I posted to construct the HTML for the body of the email and then use this.
Code:
.HTMLBody = strHTML
 
Upvote 0
Nevermind I figured it out. This works perfect except that it makes the background of the text grey but that is no big deal. Thank you!
 
Upvote 0
That site might be handy but the HTML it generated has a lot of unneeded stuff in it.:eek:

You'll need to play with the HTML to get it exactly as you want.:)

PS Pretty sure you don't need all of the 'style' stuff.
 
Upvote 0

Forum statistics

Threads
1,223,632
Messages
6,173,469
Members
452,516
Latest member
archcalx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top