Add default Outlook e-mail signature with Excel without displaying e-mail first
[ul]I need a method to send Outlook e-mails from Excel, without having to display the e-mail to retrieve the default signature:[/ul]
I used the method below to achieve this with a custom signature, but could not do it with the default signature.
How can Environ("appdata") be incorporated in the MySignature.htm file?
I used the code be Ron de Bruin and modified it slightly to be able to include a custom signature with a picture. In order for the code to work properly I had to change a line in the MySignature.htm file (found method on the internet, but can’t remember the source).
I had to change the following line in the MySignature.htm file:
<v:imagedata src="MyCompany_files/image001.jpg" o:title=""/>
To:
<v:imagedata src="C:\Users\vanhunk\AppData\Roaming\Microsoft\Signatures\MySignature_file s\image001.jpg" o:title=""/>
My aim is to be able for anyone using the workbook to send e-mails to have their own default e-mail signature displayed, without having to display the e-mail in order to get the default signature.
The question is thus how, if at all possible, can I use something like Environ("appdata") instead of C:\Users\vanhunk\AppData\Roaming in the MySignature.htm file?
Thank you very much.
Regards,
vanhunk
Code:
Sub Mail_Outlook_With_Signature_Html()
Code:
' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2013
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SigString As String
Dim Signature As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Please visit this website to download the new version.<br>"
SigString = Environ("appdata") & "\Microsoft\Signatures\MySignature.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
On Error Resume Next
With OutMail
.To = "vanhunk@xyz.co.za"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.HTMLBody = strbody & "<br>" & Signature
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function GetBoiler(ByVal sFile As String) As String
'Dick Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function