VBA Outlook Email with Signature

labonisimo

New Member
Joined
Mar 9, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hi there,

I am using an excel template to send emails from excel. It all works fine but does not add my standard signature to it. I tweaked it a little, however doesnt do what it should do. It now adds my signature but not correctly (doesnt show images and shows hyperlinks.

Maybe you can help me fix it.

VBA Code:
Option Explicit

Sub Send_Mails()
Dim emailMail As Object, signature As String
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Send_Mails")
Dim i As Integer

Dim OA As Object
Dim msg As Object

Set OA = CreateObject("outlook.application")
Set emailMail = OA.CreateItem(0)

Dim last_row As Integer
last_row = Application.CountA(sh.Range("A:A"))

For i = 2 To last_row
With emailMail
.Display
End With
signature = emailMail.Body

    Set msg = OA.CreateItem(0)
    msg.To = sh.Range("A" & i).Value
    msg.cc = sh.Range("B" & i).Value
    msg.Subject = sh.Range("C" & i).Value
    msg.Body = sh.Range("D" & i).Value & signature
    
    
    
    If sh.Range("E" & i).Value <> "" Then
        msg.attachments.Add sh.Range("E" & i).Value
    End If
    
    msg.send
    
    sh.Range("F" & i).Value = "Sent"

Next i

MsgBox "An alle Mitarbeiter verschickt"


End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi there,

I am using an excel template to send emails from excel. It all works fine but does not add my standard signature to it. I tweaked it a little, however doesnt do what it should do. It now adds my signature but not correctly (doesnt show images and shows hyperlinks.

Maybe you can help me fix it.

VBA Code:
Option Explicit

Sub Send_Mails()
Dim emailMail As Object, signature As String
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Send_Mails")
Dim i As Integer

Dim OA As Object
Dim msg As Object

Set OA = CreateObject("outlook.application")
Set emailMail = OA.CreateItem(0)

Dim last_row As Integer
last_row = Application.CountA(sh.Range("A:A"))

For i = 2 To last_row
With emailMail
.Display
End With
signature = emailMail.Body

    Set msg = OA.CreateItem(0)
    msg.To = sh.Range("A" & i).Value
    msg.cc = sh.Range("B" & i).Value
    msg.Subject = sh.Range("C" & i).Value
    msg.Body = sh.Range("D" & i).Value & signature
   
   
   
    If sh.Range("E" & i).Value <> "" Then
        msg.attachments.Add sh.Range("E" & i).Value
    End If
   
    msg.send
   
    sh.Range("F" & i).Value = "Sent"

Next i

MsgBox "An alle Mitarbeiter verschickt"


End Sub
have you tried changing your .body statements to .htmlbody
 
Upvote 0
Thank you. Already a big hint. It does not show it formatted correctly. Only problem, it doesn show images and icons.
are you able to attach an image of how it looks and how you would expect it toll if not doing theough vba
 
Upvote 0
are you able to attach an image of how it looks and how you would expect it toll if not doing theough vba
It basically saying that the linked image cannot be shown.
 

Attachments

  • Unbenannt.PNG
    Unbenannt.PNG
    1.5 KB · Views: 17
Upvote 0
Hi There,

Its a bit old thread but posting it anyway. I am fairly new to VBA but faced the same issue a couple of months ago.

I have updated your code as follows (below part only) and it works fine for me. now pick the default signature with links and proper images.

Set OA = CreateObject("outlook.application")
Set emailMail = OA.CreateItem(0)

For i = 2 To last_row

Set msg = OA.CreateItem(0)

With msg
.To = sh.Range("A" & i).Value
.CC = sh.Range("B" & i).Value
.Subject = sh.Range("C" & i).Value
.Display
.HTMLBody = sh.Range("D" & i).Value _
& .HTMLBody

End With
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,212
Members
448,874
Latest member
b1step2far

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