Ok, thank you for trying
I also did not find anything
A small side question.
I run a function to import the signature after the body
FindFirstFile = Dir$(Environ("appdata") & "\Microsoft\Signatures\" & "*.htm")
If (FindFirstFile <> "") Then
SigString = Environ("appdata") & "\Microsoft\Signatures\" & FindFirstFile
End If
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
OutMail:
With OutMail
.display
.To = ..
.Cc = ...
.Subject = ....
.HTMLBody = "Hello,<br><br>" _
& RangetoHTML(rng) & "<br>" _
& "Thank you.<br><br>" & Signature
.Attachments.Add ActiveWorkbook.FullName
End With
RangetoHTML(rng):
Function RangetoHTML(rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
'Copy the range and create a new workbook to past the data in
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial Paste:=1
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
'Publish the sheet to a htm file
With TempWB.PublishObjects.Add(SourceType:=xlSourceRange, fileName:=TempFile, Sheet:=TempWB.Sheets(1).Name, Source:=TempWB.Sheets(1).UsedRange.Address, HtmlType:=xlHtmlStatic)
.Publish (True)
End With
'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", "align=left x:publishsource=")
'Close TempWB
RangetoHTML = Replace(RangetoHTML, "<!--[if !excel]> <![endif]-->", "")
'removes a space before the range
TempWB.Close SaveChanges:=False
'Delete the htm file we used in this function
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
Function GetBoiler(ByVal sFile As String) As StringDim 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
I have recently added a picture into the signature, but after the script runs the picture gives an error "This picture can't be displayed"
Any ideas how to fix it ?
Thanks.