VBA code to add company logo at the end of the email with attachements

AccountantHarry

New Member
Joined
Oct 13, 2019
Messages
18
Hi

I have a macro which I wrote from watching a couple of YouTube videos, it works however, I would like to add the company logo at the bottom of the email, the image is saved in W:\company\logo.jpg. My codes are as follows:

Sub send_email_with_attachments()


On Error Resume Next

Dim o As Outlook.Application
Set o = New Outlook.Application

Dim omail As Outlook.MailItem

Dim i As Long

For i = 13 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row

Set omail = o.CreateItem(olMailItem)


With omail

.To = Cells(i, 1).Value
.CC = Cells(i, 2).Value
.Subject = Cells(i, 3).Value
.Body = "Hi " & Cells(i, 4).Value & vbNewLine & vbNewLine & Cells(i, 5).Value & vbNewLine & vbNewLine & Cells(i, 6).Value & "Kind regards" & vbNewLine & "Harriet"
.Attachments.Add Cells(i, 7).Value
.Attachments.Add Cells(i, 8).Value
.Attachments.Add Cells(i, 9).Value


.Display


End With
Next

End Sub




Please help.
 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Try this:

Adjust the image size in numbers in red.
Code:
Sub send_email_with_attachments()
  On Error Resume Next
  Dim o As Outlook.Application, omail As Outlook.MailItem, i As Long
  Dim sBody As String
  Set o = New Outlook.Application
  For i = 13 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
    Set omail = o.CreateItem(olMailItem)
    With omail
      .To = Cells(i, 1).Value
      .CC = Cells(i, 2).Value
      .Subject = Cells(i, 3).Value
      sBody = "Hi " & Cells(i, 4).Value & "<br><br>" & _
                      Cells(i, 5).Value & "<br><br>" & _
                      Cells(i, 6).Value & "Kind regards" & "<br><br>"
      .Attachments.Add "W:\company\logo.jpg"
      .Attachments.Add Cells(i, 7).Value
      .Attachments.Add Cells(i, 8).Value
      .Attachments.Add Cells(i, 9).Value
      .HTMLBody = "<html>" & "******>" & sBody & _
                    "<img src=cid:logo.jpg height=[COLOR=#ff0000]150 [/COLOR]width=[COLOR=#ff0000]150[/COLOR]>" & _
                    "</body>" & "</html>"
      .Display
    End With
  Next
End Sub
 
Last edited:
Upvote 0
Hi

It only shows ******>img src=cid:logo.jpg height=150 width=150>
and the attachments, the body of the email has disappear totally.

Regards







Try this:

Adjust the image size in numbers in red.
Code:
Sub send_email_with_attachments()
  On Error Resume Next
  Dim o As Outlook.Application, omail As Outlook.MailItem, i As Long
  Dim sBody As String
  Set o = New Outlook.Application
  For i = 13 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
    Set omail = o.CreateItem(olMailItem)
    With omail
      .To = Cells(i, 1).Value
      .CC = Cells(i, 2).Value
      .Subject = Cells(i, 3).Value
      sBody = "Hi " & Cells(i, 4).Value & "

" & _
                      Cells(i, 5).Value & "

" & _
                      Cells(i, 6).Value & "Kind regards" & "

"
      .Attachments.Add "W:\company\logo.jpg"
      .Attachments.Add Cells(i, 7).Value
      .Attachments.Add Cells(i, 8).Value
      .Attachments.Add Cells(i, 9).Value
      .HTMLBody = "" & "******>" & sBody & _
                    "[IMG]https://www.mrexcel.com/forum/logo.jpg[/IMG]150 width=[COLOR=#ff0000]150[/COLOR]>" & _
                    "" & ""
      .Display
    End With
  Next
End Sub
 
Upvote 0
The forum editor modified my code. :mad:

Try the following:

Change these lines:

Code:
      .HTMLBody = "<html>" & "******>" & sBody & _
                    "<img src=cid:logo.jpg height=150 width=150>" & _
                    "</body>" & "</html>"


For these:

Code:
.HTMLBody = "< html >" & "< body >" & sBody & _
                    "< img src=cid:logo.jpg height=150 width=150 >" & _
                    "< /body >" & "< /html >"

After and before each symbol <I had to put a space, otherwise the editor makes changes. Please remove those spaces.
It should look like this:

71c998fb28523a3f0e597b91c015b08f.jpg
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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