1

Hi I am trying to create a Macro which can send mail with multiple embedded images. I want to add different url in each image and embed it as a single image in a table. Once the user click on these different part of single image it should direct him to it's respective website. Please help me with the vba macro code.

I want the said code as an extension of my code in below given question or code pasted here.

How to Change width and height of embedded image in mail using Cell values

Thanks in advance.

Sub SendMail()

Dim olApp As Object
Dim olMail As Object



For I = 2 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row

With ws
 Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(olMailItem)


End With


With olMail
.To = Cells(I, 2).Value
.cc = Cells(I, 3).Value
.bcc = Cells(I, 4).Value
.Subject = Cells(I, 5).Value
.Body = Cells(I, 6).Value


On Error Resume Next
.Attachments.Add Cells(I, 7).Value
.HTMLBody ="<HTML><center> <img src ="""&Cells(I,10).Value&"""width="""&Cells(I, 8).Value&""" height=""" & Cells(I, 9).Value & """ ><br>"


On Error GoTo 0

.Display
.Send

End With

Next

Set olMail = Nothing
Set olApp = Nothing

 MsgBox "Mails Sent Successfully"


End Sub
Community
  • 1
  • 1
Rehaan
  • 23
  • 5
  • So what is the error/problem? - `On Error Resume Next` hides important error details: remove it. Using an `` tag is not embedding an image, its linking to one - which many email clients will block without user interaction. – Alex K. Mar 24 '16 at 10:52
  • Thanks Alex for the valuable inputs. If i remove what should be my code to pick image from my the path on my pc – Rehaan Mar 24 '16 at 11:03
  • @Rehaan: Here is the code you can use to attach a picture to your email and embed it into your HTML email: http://stackoverflow.com/questions/36058862/how-to-embed-image-placed-inside-the-excel-into-the-htmlbody-of-vbascript/36060411#36060411 – Ralph Mar 24 '16 at 14:10
  • Thanks Ralph, but as pointed out by Alex that that " Using an tag is not embedding an image, its linking to one - which many email clients will block without user interaction" i wanted to know the alternate code so that e-mail application should not block my image. And also would like to have code for the description given in my above question. "Multiple Embedded Images in mail with different url (Excel VBA)" – Rehaan Mar 24 '16 at 14:46
  • before you spend so much time trying to do this, did you consider the user experience? how will the email recipient even know that different parts of the image have different links? You can't have hover effects in email as far as I know. Also, the chances that everyone's email clients will even display the image, whether embedded or linked, is slim to nil. [This post may be helpful](http://stackoverflow.com/questions/20713626/hover-image-animate-in-news-letter-email) – MilkyTech Mar 26 '16 at 17:25
  • @Chris M Image say "Click Here to Enrol", "Download PDF" etc. Which should have it's respective link. – Rehaan Mar 30 '16 at 18:47
  • Please somebody help – Rehaan Apr 09 '16 at 05:10
  • Please somebody help – Rehaan Apr 14 '16 at 02:54

0 Answers0