Need HELP: Insert image in the email body based on the path provided in the excel

aman2059

Board Regular
Joined
Jan 17, 2016
Messages
75
Hi All,

I am trying to add images in the email body in my mass email macro but unfortunately, I have no success as of yet.

So in my excel, I have the HTML images links for different emails in the "column L". For each recipient, the image could be different. I accordingly paste the path

For example - D:\Apps\xp\Desktop\Doc1.htm

Please see my code below, could any one please help me with the code on how to embed image in the email body.

I need to add the image after the email.

Code:
Sub togenerateemails()
 
 
    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range
    Dim rng As Range
    Dim strbody As String
    Dim pic As String
    Dim Hlink As String, Hlink2 As String
  
    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")
 
    On Error GoTo cleanup
  
    'Windows("master.xlsx").Activate
    'Worksheets("Sheet2").Activate
    Sheets("to create emails").Activate
    'Worksheets("Current report").Activate
  
    For Each cell In Columns("C").Cells.SpecialCells(xlCellTypeConstants)
        If cell.Value Like "?*@?*.?*" And _
           LCase(Cells(cell.Row, "g").Value) = "yes" Then
 
            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
            .SentOnBehalfOfName = "Aman"
                .To = Cells(cell.Row, "e").Value
                 .cc = Cells(cell.Row, "h").Value
                  .Attachments.Add (Cells(cell.Row, "K").Value)
              
               If Cells(cell.Row, "D") = "False" Then
              
               .Subject = "Accounts"     
                body = "Dear " & Cells(cell.Row, "F").Value & "," & "" _
                      & vbNewLine & vbNewLine & _
"<p><font face=""Calibri"" size=""2"" color=""black"">"EMAIL BODY " </A>. </P>" _

 
                .HTMLBody = body
                             
                ElseIf Cells(cell.Row, "D") = "True" Then
              
               .Subject = " Accounts"
               
                body = "Dear " & Cells(cell.Row, "F").Value & "," & "" _
                      & vbNewLine & vbNewLine & _               
"<p><font face=""Calibri"" size=""2"" color=""black"">"EMAIL BODY " </A>. </P>" _
                    
 
                .HTMLBody = body
              
               End If
              
                .Display
              
                '(Remove the line below if the email has to be reviewed first before sending'
                'SendKeys "^{ENTER}"
          
            End With
            On Error GoTo 0
            Set OutMail = Nothing
        End If
    Next cell
 
cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
  
MsgBox ("All the emails have been drafted")
 
End Sub
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Pasting the code again

Code:
Sub togenerateemails()
 
 
    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range
    Dim rng As Range
    Dim strbody As String
    Dim pic As String
    Dim Hlink As String, Hlink2 As String
  
    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")
 
    On Error GoTo cleanup
  
    'Windows("master.xlsx").Activate
    'Worksheets("Sheet2").Activate
    Sheets("to create emails").Activate
    'Worksheets("Current report").Activate
  
    For Each cell In Columns("C").Cells.SpecialCells(xlCellTypeConstants)
        If cell.Value Like "?*@?*.?*" And _
           LCase(Cells(cell.Row, "g").Value) = "yes" Then
 
            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
            .SentOnBehalfOfName = "Aman"
                .To = Cells(cell.Row, "e").Value
                 .cc = Cells(cell.Row, "h").Value
                  .Attachments.Add (Cells(cell.Row, "K").Value)
              
               If Cells(cell.Row, "D") = "False" Then
              
               .Subject = "Accounts"     
                body = "Dear " & Cells(cell.Row, "F").Value & "," & "" _
                      & vbNewLine & vbNewLine & _
"<p><font face=""Calibri"" size=""2"" color=""black"">"EMAIL BODY " </A>. </P>" _

 
                .HTMLBody = body
                             
                ElseIf Cells(cell.Row, "D") = "True" Then
              
               .Subject = " Accounts"
               
                body = "Dear " & Cells(cell.Row, "F").Value & "," & "" _
                      & vbNewLine & vbNewLine & _               
"<p><font face=""Calibri"" size=""2"" color=""black"">"EMAIL BODY " </A>. </P>" _
                    
 
                .HTMLBody = body
              
               End If
              
                .Display
              
                '(Remove the line below if the email has to be reviewed first before sending'
                'SendKeys "^{ENTER}"
          
            End With
            On Error GoTo 0
            Set OutMail = Nothing
        End If
    Next cell
 
cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
  
MsgBox ("All the emails have been drafted")
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,186
Members
452,615
Latest member
bogeys2birdies

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