Option Explicit
Sub sendMail()
On Error Resume Next
Dim xOutApp As Object, xOutMail As Object, xRg As Range
Dim TempFilePath$, xHTMLBody$
Set xRg = [B1:C11]: If xRg Is Nothing Then Exit Sub
Dim rép%, sigstring$, signature$, f$
sigstring = Environ("appdata") & "\Microsoft\Signatures\"
f = Dir(sigstring & "*.htm")
signature = getboiler(sigstring & f)
Application.ScreenUpdating = 0
Dim olMailItem As Object, olByValue As Object
Set xOutApp = CreateObject("outlook.application")
Set xOutMail = xOutApp.CreateItem(olMailItem)
Call createJpg(ActiveSheet.Name, xRg.Address, "Résultat")
TempFilePath = Environ$("Public") & "\"
xHTMLBody = "<span LANG=EN>" _
& "<p class=style2><span LANG=EN><font FACE=Calibri SIZE=3>" _
& "hi, <br><br>Please find....> <br>" & (xRg) & "<br><br>"
rép = MsgBox("Est-ce une mise à jour du dossier ?", 4, "Question")
With xOutMail
If rép = 6 Then [C3] = [C3] & " - Mise à jour" _
Else .Subject = "Résultat - " & [Feuil2!C3]
.HTMLBody = xHTMLBody & signature
.Attachments.Add TempFilePath & "Résultat.jpg", olByValue
.To = "toto@hotmail.com"
.Cc = "tati@hotmail.com"
.Display
End With
Kill "C:\Users\Public\Résultat.jpg"
Application.ScreenUpdating = -1
Workbooks("Travail").Save
End Sub
Sub createJpg(SheetName$, xRgAddrss$, nameFile$)
Dim xRgPic As Range, xShape As Shape
ThisWorkbook.Activate: Worksheets(SheetName).Activate
Set xRgPic = ThisWorkbook.Worksheets(SheetName).Range(xRgAddrss)
xRgPic.CopyPicture
With ThisWorkbook.Worksheets(SheetName).ChartObjects.Add(xRgPic.Left, xRgPic.Top, xRgPic.Width, xRgPic.Height)
.Activate
For Each xShape In ActiveSheet.Shapes
xShape.Line.Visible = msoFalse
Next
.Chart.Paste: .Chart.Export Environ$("Public") & "\" & nameFile & ".jpg", "JPG"
End With
Worksheets(SheetName).ChartObjects(Worksheets(SheetName).ChartObjects.Count).Delete
Set xRgPic = Nothing
End Sub
Function getboiler(fpath$) As String
Dim fso As Object, ts As Object
Set fso = CreateObject("scripting.filesystemobject")
Set ts = fso.getfile(fpath).openastextstream(1, -2)
getboiler = ts.readall: ts.Close
End Function