vba - How to make Text Body in VB <b> not working -
i have code send email excel. info taken cells. trying make "j4" bold says symtex error when use . sorry i'm pretty new vba please explain if i'm complete noob. code is:
sub sendmassemail() row_number = 1 doevents row_number = row_number + 1 dim mail_body_message string dim full_name string dim twitter_code string mail_body_message = sheet1.range("j2") & vbnewline & sheet1.range("j3") & vbnewline & sheet1.range("j4") & vbnewline & sheet1.range("j5") & vbnewline & sheet1.range("j6") full_name = sheet1.range("b" & row_number) twitter_code = sheet1.range("d" & row_number) mail_body_message = replace(mail_body_message, "replace_name_here", full_name) mail_body_message = replace(mail_body_message, "promo_code_replace", twitter_code) msgbox mail_body_message call sendtheemail(sheet1.range("a" & row_number), "this subject", mail_body_message) loop until row_number = 5 msgbox "**emails sent**" end sub
the problem here variable mail_body_message text. there no way indicate when bold or color. must use html in email achieve want. example:
replace
mail_body_message = sheet1.range("j2") & vbnewline & sheet1.range("j3") & vbnewline & sheet1.range("j4") & vbnewline & sheet1.range("j5") & vbnewline & sheet1.range("j6")
with
mail_body_message = "<html><body><font size=3>" & sheet1.range("j2") & vbnewline & sheet1.range("j3") & vbnewline & "<b>" & sheet1.range("j4") & "</b>" & vbnewline & sheet1.range("j5") & vbnewline & sheet1.range("j6") & "</font></body></html>"
there more work need do. must set mail item's body format olformathtml. must set htmlbody of message variable. basically, you'll need this:
set mitem = outlookapp.createitem(olmailitem) mitem .to = emailaddr .subject = subj .bodyformat = olformathtml .htmlbody = mail_body_message .send end
you can change color of text html font tags. example:
mail_body_message = "<font color='red'>" & vbavariable & "</font>"
Comments
Post a Comment