1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| Option Explicit
Sub Mail_Facturation()
ThisWorkbook.Activate ' Évite que la macro ne se lance sur un autre fichier ouvert
Dim Messagerie As Object, Email As Object, Objet$, Message$, Plage As Range, Image$, f As Worksheet
Set f = ThisWorkbook.Sheets("Facturation")
If MsgBox("Envoyer un mail au contentieux ? ", vbYesNo + vbQuestion, "Facturation") = vbYes Then
Image = Environ("TEMP") & "\Image.jpg"
'-------------------------------------------------------------------------------------
'Message du mail
Message = "<span style='font-family: Calibri Light; font-size: 11pt;'>" & _
"Bonjour,<br><br>" & _
"Avons-nous reçu les paiements ? Voir colonne Etat<br><br>" & _
"Meilleures salutations<br>" & _
Application.UserName & "<br><br></span>" & _
"<img src='" & Mid(Image, InStrRev(Image, "\") + 1) & "' alt='Image'>"
'-------------------------------------------------------------------------------------
Application.ScreenUpdating = True ' Forcer à true sinon l'image sera blanche
'-------------------------------------------------------------------------------------
'le tableau a copier
Set Plage = Range("TS_Facturation[[#headers],[#data],[Année]:[Descriptif]]")
If WorksheetFunction.CountA(Plage.Columns(1)) > 2 Then
Set Plage = Plage.Resize(Plage.Rows.Count + Plage.Row - 2).Offset(-Plage.Row + 2)
Else 'si il n'y a pas de dats dans le TS
Set Plage = f.[a2].Resize(Plage.Row - 2, Plage.Columns.Count)
End If
'-------------------------------------------------------------------------------------
Plage.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
'-------------------------------------------------------------------------------------
'Object chart pour export de la capture
With f.ChartObjects.Add(Left:=Plage.Left, Top:=Plage.Top, Width:=Plage.Width, Height:=Plage.Height)
.Activate
Do While .Chart.Pictures.Count = 0: .Chart.Paste: Loop
.Chart.Export Image, "JPG"
.Delete
End With
'-------------------------------------------------------------------------------------
'Object Mail Outlook
'Objet du mail
Objet = "Fichier de facturation mise à jour des sommes reçues - " & CStr(f.Range("Cell_Facturation_Cmde").Text) & " - " & CStr(f.Range("Cell_Facturation_Adresse").Text)
' Création session Outlook
Set Messagerie = CreateObject("Outlook.Application")
Set Email = Messagerie.CreateItem(0)
With Email
.To = "contentieux@zurbuchensa.ch"
.CC = ""
.Subject = Objet
.Attachments.Add Image ' une premiere fois pour qu'il soit dipo sur le serveur du mail
.Attachments.Add Image ' une 2d fois si on veux qu'elle soit en piece jointe aussi
.HTMLBody = Message
.Display
End With
'-------------------------------------------------------------------------------------
' Supprimer l'image temporaire
If Dir(Image) <> "" Then Kill Image
Messagerie.ActiveWindow.WindowState = 0 ' 0=Maximized, 1=Minimized, 2=Normal
End If
Set Email = Nothing
Set Messagerie = Nothing
Set Plage = Nothing
End Sub |
Partager