Hello All,
I'm trying to add an .jpg to the body of this email, but the picture is not showing up.
It says, "The linked image cannot be displayed." I stepped thru the code and I know the path and name are good.
Add picture into body of email
-
- Administrator
- Posts: 79317
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Add picture into body of email
Since you're using code, could you post it - or at least the relevant part of it?
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 256
- Joined: 09 May 2020, 14:00
Re: Add picture into body of email
Oops, sorry, I thought I had.
Code: Select all
Sub SendMail()
Dim Fname As String: Fname = "C:\Users\gb\Desktop\HappyBirthday.jpg"
Dim MyEmail As MailItem: Set MyEmail = Application.CreateItem(olMailItem)
With MyEmail
.To = ""
.Subject = "Happy Birthday"
.HTMLBody = "Dear," & _
"<p>" & "Wishing you all the best." & _
"<p>" & "<img src=""cid:HappyBirthday.jpg""height=360 width=520>"
.BodyFormat = olFormatHTML
.Display
End With
End Sub
-
- Administrator
- Posts: 79317
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Add picture into body of email
Try this:
Code: Select all
Sub SendMail()
Dim Fname As String: Fname = "C:\Users\gb\Desktop\HappyBirthday.jpg"
Dim MyEmail As MailItem: Set MyEmail = Application.CreateItem(olMailItem)
Dim doc As Object ' Word document
Dim rng As Object ' Word range
With MyEmail
.To = ""
.Subject = "Happy Birthday"
.BodyFormat = olFormatHTML
.Display
Set doc = .GetInspector.WordEditor
doc.Content.InsertAfter "Dear,"
doc.Content.InsertParagraphAfter
doc.Content.InsertAfter "Wishing you all the best."
doc.Content.InsertParagraphAfter
Set rng = doc.Content
rng.Collapse Direction:=0 ' wdCollapseEnd
rng.InlineShapes.AddPicture FileName:=Fname
End With
End Sub
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 256
- Joined: 09 May 2020, 14:00
Re: Add picture into body of email
Thank you Hans. This works great.