VBA: Embedding a Picture in an Outlook Email

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
21,612
Office Version
  1. 365
Platform
  1. Windows
Is it at all possible to embed a picture in an email? I've tried...

Code:
.HtmlBody = " < img src=""C:/Users/Domenic/Desktop/Sample.png"" > "

However, while the picture gets inserted in the email, it's not actually embedded. As a result, when the recipient receives the email, the image is not displayed.
 
Thanks Domenic.

Worked fine, and I found the problem - the HTML in the code I tested with was wrong.

So my fault really.:oops:
 
Last edited:
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Norie, thank you very much. I really appreciate your help. :)
 
Upvote 0
Thanks Domenic.

Worked fine, and I found the problem - the HTML in the code I tested with was wroing.:)


Hi Norie

I heard you're good at this. Now does your code copy a range of cells in excel that is text and "pastes" it into the body of the email as a photo? Just like the basic Copy-Paste as Picture function?

Hoping you could help me out.

Thanks,
Josh
 
Upvote 0
Josh

The code in this thread, which isn't mine, is for inserting an image into an email.

No copying of text or pasting as picture.

What is it you are trying to do?
 
Upvote 0
Josh

The code in this thread, which isn't mine, is for inserting an image into an email.

No copying of text or pasting as picture.

What is it you are trying to do?


Hi Norie

I want to be able to email my sales agents the list of their pending requirements. I have a combo list box with their names and upon choosing a name it shows from Range B6:i26 their status. I have an email button that emails the selected seller. I want it to take Range B6:i26 and "paste" it into the body of the email as a photo. Would you know how to do this?

Here's my code:

Code:
Private Sub ComboBox1_Change()


End Sub


Private Sub cboBuyer_Change()


End Sub


Private Sub Send_Email_Click()
sendemail
End Sub
Public Function sendemail()
On Error GoTo ende
esubject = "Pending Requirements of " & Range("B6").Value
sendto = Range("I11").Value
ebody = "Dear " & Chr(10) & Chr(10) & "This is to remind you of your client's pending requirements. Please see below:" & Chr(10) & Chr(10) & Chr(10) & Chr(10) & "Please submit these as soon as possible to avoid any delay." & Chr(10) & Chr(10) & "Thank you,"


Set app = CreateObject("Outlook.Application")
Set itm = app.CreateItem(0)


With itm
.Subject = esubject
.To = sendto
.body = ebody
.Display
End With
Set app = Nothing
Set itm = Nothing




ende:
End Function


Private Sub CommandButton1_Click()
   Range("I11:i18") = 0
   Range("I9") = "Select Name"
   Range("L10") = 5
End Sub
 
Upvote 0
Sorry to bump this up, but I'm trying to use the code posted by Norie on page 2 and I can't get it to work. I the image shows as an attachment fine, but in the body of the email, all I get is a red X.

Here is my code. Is there something wrong? Can somebody help me out?

Or should I have started a new thread?

NOTE: I USED [ AND ] IN THE HTML BODY INSTEAD OF <> TO PREVENT THE BOARD FROM TRYING TO TURN IT INTO A PICTURE.

Code:
<igm src="cid:'C:\Users\NGerdes\Pictures\GoalSheetHeader.jpg'"<br">

Sub mailTest()
    


'Add reference to MS Outlook x.x Object Library
'Picture to be added as an attachment and modified src location for each embedded picture.


Dim oApp As Outlook.Application
Dim oEmail As MailItem
Dim colAttach As Outlook.Attachments
Dim oAttach As Outlook.Attachment
    'create new Outlook MailItem
    Set oApp = CreateObject("Outlook.Application")
    Set oEmail = oApp.CreateItem(olMailItem)
    'add graphic as attachment to Outlook message
    'change path to graphic as needed
    Set colAttach = oEmail.Attachments
    Set oAttach = colAttach.Add("C:\Users\NGerdes\Pictures\GoalSheetHeader.jpg")
    oEmail.Close olSave
    'change the src property to 'cid:your picture filename'
    'it will be changed to the correct cid when its sent.
    oEmail.HTMLBody = "[IMG src=cid:'C:\Users\NGerdes\Pictures\GoalSheetHeader.jpg']"
    
    oEmail.Save
    oEmail.Display    'fill in the To, Subject, and Send. Or program it in.
    Set oEmail = Nothing
    Set colAttach = Nothing
    Set oAttach = Nothing
    Set oApp = Nothing
End Sub

Also: Using: Excel 2010 / Outlook 2010 / Windows 7 32bit</igm>
 
Upvote 0
Just like mine was in an earlier post.:)f
 
Upvote 0
Yep. I put src=cid:'C:\Users\NGerdes\Pictures\GoalSheetHeader.jpg' instead of simple putting src=cid:'GoalSheetHeader.jpg'

I tried to make it to embed two different images. Couldn't get that figured out. So do you have anything on that?
 
Upvote 0

Forum statistics

Threads
1,215,695
Messages
6,126,262
Members
449,307
Latest member
Andile

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