'### Constante d'un fichier temporaire qui sera détruit par la suite ###
Const TEMPO As String = "c:\___pmoTemporaire.jpg"
Sub InsererPlageDansMail()
Call PMO_MakeJPG
End Sub
Sub PMO_MakeJPG(Optional dummy As Byte)
Dim R As Range
Dim CO As ChartObject
On Error GoTo Erreur
If TypeName(Selection) <> "Range" Then
MsgBox "Veuillez sélectionner une plage contenant éventuellement une image, un graphique."
Exit Sub
End If
Set R = Selection
R.CopyPicture xlScreen, xlBitmap
With R
Set CO = ActiveSheet.ChartObjects.Add( _
.Left, .Top, .Width + 8, .Height + 8)
End With
With CO.Chart
.Paste
.Export Filename:=TEMPO
End With
CO.Delete
Set CO = Nothing
Call PMO_PlageMail
Exit Sub
Erreur:
MsgBox "Erreur : " & Err.Number & vbCrLf & Err.Description
End Sub
Sub PMO_PlageMail(Optional dummy As Byte)
Dim OUT As Outlook.Application
Dim IT As Outlook.MailItem
Dim msgDebut$
Dim msgFin$
Dim A$
Set OUT = CreateObject("Outlook.Application")
Set IT = OUT.CreateItem(olMailItem)
'////////////////////////////////////////////////////////////////
'/// Adapter les lignes ci-dessous SI texte à ajouter au mail ///
'/// Pour ne rien ajouter : msgDebut$ = "" ET msgFin$ = "" ///
msgDebut$ = "Bonjour," 'en-tête
msgFin$ = "Cordialement." 'pied du texte
'////////////////////////////////////////////////////////////////
On Error GoTo Erreur
If Dir(TEMPO) <> "" Then
A$ = msgDebut$ & "<br><br><img src='" & TEMPO & _
"'><br><br>" & msgFin$ & "</BODY></HTML>"
With IT
.Display
.HTMLBody = A$
.Subject = "essai"
.To = "toto@zaza.fr" 'adapter le destinataire
.Send
End With
End If
Erreur:
On Error Resume Next
Set IT = Nothing
Set OUT = Nothing
Kill TEMPO
If Err <> 0 And Err <> 287 And Err <> 53 Then _
MsgBox "Erreur : " & Err.Number & vbCrLf & Err.Description
End Sub