I am trying to send an Outlook email from Excel VBA. I am attaching a signature file.
I have a signature in Outlook that contains an image.
The code below retrieves a signature from the Signatures folder. AppDataRoamingMicrosoftSignatures)
After running the code I have in place of the image “The picture can’t be displayed”.
Sub Mailtest(Website)
Dim OApp As Object 'DimOutlook forEmail
Dim OMail As Object 'DimMail for Email
Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)
With OMail
.Display
Application.Wait VBA.Now + VBA.TimeValue("00:00:02")
End With
'Signature = Mid(OMail.HTMLBody, 1, Len(OMail.HTMLBody) - 13)
'OMail.HTMLBody = "Auto" & Signature
OMail.To = Website
OMail.CC = "TESTTEST"
OMail.Subject = "WISLA"
sSignature = ReadSignature("TEST_Signature.htm")
sSignature = Replace(sSignature, "%20", " ")
OMail.HTMLBody = "Example" & sSignature
'OMail.Display 'to show mail
End Sub
Public Function ReadSignature(sigName As String) As String
Dim oFSO, oTextStream, oSig As Object
Dim appDataDir, sig, sigPath, filename As String
appDataDir = Environ("APPDATA") & "MicrosoftSignatures"
sigPath = appDataDir & "" & sigName
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextStream = oFSO.OpenTextFile(sigPath)
sig = oTextStream.readall
filename = Replace(sigName, ".htm", "") & "_files/"
sig = Replace(sig, filename, appDataDir & "" & filename)
ReadSignature = sig
End Function
The signature is added using:
How do I make the email I send show an image?