Put an image in an HTMLBody for email

corquando

Board Regular
Joined
Jan 8, 2009
Messages
82
Greetings!

First, I just want to say I've never come here and not found an answer to any issue I was facing, either by posting (rarely) or by simply searching some keywords. This place is a goldmine!

So, proper supplications having been performed, I now present this poser:

I have a database which I am merging to an HTMLBody for emailing. That much is elementary (thanks to extensive discussion here just last week!)

What I cannot seem to find is a way that I can insert an image from the same folder wherein my database sits into the emails. I also have the image on a sheet in the workbook itself.

I have seen some code that purports to do this, but it makes my brain hurt - it asks to reference Microsoft CDO 1.21 Library which I don't have (Excel 2007). The code I've found is 6+ years old which means that the reference must be obsolete(?)

As well, it involved an InputBox used to choose from a selection of images - I don't need any of that.

Here's what I have:

Rich (BB code):
StrBod = "< HTML >"
StrBod = StrBod & "< HEAD >< /HEAD >"
StrBod = StrBod & "< BODY >" 
StrBod = StrBod & "Dear " + NameVar + ",< p >< p >"
StrBod = StrBod & "You rock.< p >< p >"
StrBod = StrBod & "We are pleased to have you as a member of this exclusive club.< p >< p >"
StrBod = StrBod & "Director A. Person,< p >< p >"
StrBod = StrBod & "< img src=signature.gif >,< p >< p >" 'Brain hurts here.
StrBod = StrBod & "Member Services General Director< p >< p >"
StrBod = StrBod & "People Who Rock Club< p >< p >"
StrBod = StrBod & "< /BODY >"

Spaces for obvious reasons.

NameVar is called from the dB. The usual Dim statements and all exist but I don't want to cloud the immediate issue.

Is there a way to reference the image 'signature.gif,' either by folder or by workbook/sheet/range, and get it put in there? It's the same one for every time, so there will be no variety or need for multiple choices.

I'd like to avoid having to build an entire Outlook session just for one image. Using the CDO bypass is a real time-saver, plus going through Outlook attaches my name "on behalf" and we wish to avoid any personal identifications.

Could I use an "a href = File///" statement? Just a thought . . .

Thank in advance! I'm hoping this one's as fun as the others have been.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
OK - going by history, I know that a lack of immediate reply means I've dug up a whopper.

So.

What I did was compose the text & graphics as a mail-merge .docx, and then save it as an .mht. Each go-round creates a new mail-merge doc, saves it as an .mht file and then kills it off after the (attempted) send, using the same save-as filename.

Graphics problem solved, but . . .

Now, I'm trying to get the .mht file as an HTMLbody to send in the emails.

I've tried 2 ways.

1:
Rich (BB code):
StrBod = "< HTML >"
StrBod = StrBod & "< HEAD >< /HEAD >"
StrBod = StrBod & "< BODY >"
StrBod = StrBod & "< a href =  Phile://C:\Enormous\DATA\Huge\Big\Small\MyMergeLetter.mht>< /a >"
StrBod = StrBod & "< /BODY >"
StrBod = StrBod & "< /HTML >"
 
With iMsg
       Set .Configuration = iConf
       .To = Me@MyEmail
       .CC = ""
       .BCC = ""
       .From = Test@Sample.email
       .Subject = "You Lovely Person"
       .HTMLBody = StrBod
       .Send
End With

Which gets me a blank email when I send it to myself. And, 2:

Rich (BB code):
'Usual CDO setups
 
With iMsg
       Set .Configuration = iConf
       .To = Me@MyEmail
       .CC = ""
       .BCC = ""
       .From = Test@Sample.email
       .Subject = "You Lovely Person"
       .HTMLBody = "< a href =  Phile://C:\Enormous\DATA\Huge\Big\Small\MyMergeLetter.mht>"
       .Send
End With

Which also gets me the exact same blank email.

Hopefully this is much less of a boulder to roll up the hill. And as always, I'm sure I'm missing some enormously small detail that wil make me feel rather sheepish when found.

Thanks in advance!
 
Upvote 0
Don't understand any of your 2nd post, but I will try to answer your 1st post.

To insert an image in an email the image needs to be hosted on a web server and you specify the full URL to it, like this:
Code:
.HTMLBody = "< p>First paragraph< br>New line in first paragraph< /p>" & _
                "< img src='http://www.mrexcel.com/forum/images/misc/mrexcel_logo.gif'/>" & _
                "< p>Mr Excel logo is above this paragraph< /p>"
 
Upvote 0
Yeah . . . I was trying to carve a turkey w/ a chainsaw.

I had no server I could appropriate - the trolls are jealous of their turf hereabouts. So I just went off my local machine and zip-zap there you go.

Thanks a billion!
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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