Send e-mails via VBA with embedded picture

andreeasimon

New Member
Joined
Jan 3, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have been using VBA to send e-mails to multiple contacts for a while now. I am now struggling to add also an embedded picture (logo) to my e-mails.

I tried multiple variations for the script:
1641215880234.png


I tried with .png, .img and so on. I am able to attach the picture to the e-mail, but in the body of the e-mail I am not able to see the picture (logo in this case), it is always displayed like this:

1641215975250.png

Any help would be very much appreciated!

Thanks you
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
First, attach your image to your email . . .

VBA Code:
 .Attachments.Add "c:\users\domenic\desktop\sample.png"

And then embed it like this . . .

VBA Code:
        .HTMLBody = "<br><img src='cid:sample.png'>" & _

Hope this helps!
 
Upvote 0
First, attach your image to your email . . .

VBA Code:
 .Attachments.Add "c:\users\domenic\desktop\sample.png"

And then embed it like this . . .

VBA Code:
        .HTMLBody = "<br><img src='cid:sample.png'>" & _

Hope this helps!
Thanks so very much!

I used: .AddAttachment "C:\Users\andreea-simon\Downloads\sample.PNG"

and after:
"<br>" & "<img src='cid:sample.png' >" & _

and now I have the image finally embedded!

Any change you know how to make the attachment invisible? As I do not want it to appear as an attachment, only embedded in the body of the e-mail.

Thanks again!
 
Upvote 0
To hide the attachment, set the Position argument to 0. . .

VBA Code:
        .Attachments.Add Source:="C:\Users\andreea-simon\Downloads\sample.PNG", Type:=1, Position:=0

Or, without named arguments . . .

VBA Code:
        .Attachments.Add "C:\Users\andreea-simon\Downloads\sample.PNG", 1, 0

See the following documentation for a reference . . .

 
Upvote 0
Hi,

Thanks!

The only issue is that I cannot use .Attachments.Add as I always get the bellow error:

1641290450493.png


I need to use .AddAttachment Range("H1").Value, 1, 0 (I mentioned the path for the image in cell H1 of my sheet) for it to work.
However, the attachment is still visible.

Any advice is very much appreciated!
 

Attachments

  • 1641290251873.png
    1641290251873.png
    4 KB · Views: 8
Upvote 0
What object is being referenced? Can you post a fully qualified reference?
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,496
Members
449,089
Latest member
Raviguru

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