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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| Sub MailAutomatique()
'Objects used in macro
'Outlook objects
Dim objApp As Outlook.Application
Dim objMail As Outlook.MailItem
Dim strHtml As String
Dim olExplorer As Outlook.Explorer
'Initialize outlook objects
Set olApp = GetObject("", "Outlook.application")
Set objMail = olApp.CreateItem(olMailItem)
'File System Objects
Dim oFSO As Scripting.FileSystemObject
Dim DriVe As Scripting.DriVe
Dim nOm As String
'Initialize FSO Objects
Set oFSO = New Scripting.FileSystemObject
'(1)
'Looking for the letter of the "Partage Coordination Qualité CRC" Drive which is different for every user
'If this drive exists in the computer, we look for its letter
'For each drive in the system, we look for the one which named "\\idf1pntdpt01\Partage Coordination Qualité CRC$"
'When we find it, the value of nOm is the letter of this drive
For Each DriVe In oFSO.Drives
If DriVe.ShareName = "\\idf1pntdpt01\Partage coordination qualité crc$" Or DriVe.ShareName = "\\idf1pntdpt01\Partage Coordination Qualité CRC$" _
Or DriVe.ShareName = "\\idf1pntdpt01\Partage oordination Qualité CRC$" Then
nOm = DriVe.DriveLetter
End If
Next DriVe
'(2)
'Emails details
'We define the email we want to send : subject, recipients
With objMail
.Display 'Open the Outlook Window
.Subject = "Indicateurs mensuels de qualité et productivité du CRC " & Format(DateAdd("m", -1, Date), "mmmm") & " " & Year(Date) 'Email's subject
.To = "ombeline.malone@ingdirect.fr" 'Email's recipient
End With
'(3)
'We use the letter of the drive we get earlier (1) to define where we save the pictures of charts
'Export charts as pictures
With Feuil20
.ChartObjects("Graph1").Chart.Export nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\KPIAppels.jpg", "JPG"
.ChartObjects("Graph2").Chart.Export nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\KPIEmails.jpg", "JPG"
.ChartObjects("Graph3").Chart.Export nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\DMT.jpg", "JPG"
.ChartObjects("Graph4").Chart.Export nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\FTEProd.jpg", "JPG"
.ChartObjects("Graph5").Chart.Export nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\QualiteAppels.jpg", "JPG"
.ChartObjects("Graph6").Chart.Export nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\QualiteEmails.jpg", "JPG"
.ChartObjects("Graph7").Chart.Export nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\HomogEval.jpg", "JPG"
.ChartObjects("Graph8").Chart.Export nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\PartCCObj.jpg", "JPG"
End With
'(4)
'We define the body of the email we want to send : bold, italic, undelined, font size, etc...
'We use pictures we saved earlier (3)
'Emails format
strHtml = "Bonjour, <BR><BR>"
strHtml = strHtml & "Veuillez trouver ci-dessous les indicateurs mensuels concernant la qualité et la productivité du CRC pour " & Format(DateAdd("m", -1, Date), "mmmm") & " " & Year(Date) & "." & "<BR>"
strHtml = strHtml & "Nous restons à votre disposition pour toute information complémentaire."
strHtml = strHtml & "<BR><BR><BR>"
strHtml = strHtml & "<b><u><span style="" font-size: 28""><center> INDICATEURS DE PRODUCTIVITE CRC </center></TD></span></u></b>" & "<BR><BR>"
strHtml = strHtml & "<center><img src='cid:KPIAppels.jpg'></center>" & "<BR><BR>"
strHtml = strHtml & "<center><img src='cid:KPIEmails.jpg'></center>" & "<BR><BR>"
strHtml = strHtml & "<center><img src='cid:DMT.jpg'></center>" & "<BR><BR>"
strHtml = strHtml & "<center><img src='cid:FTEProd.jpg'></center>" & "<BR><BR><BR><BR><BR><BR><BR><BR>"
strHtml = strHtml & "<b><u><span style=""font-size: 28 ""><center> INDICATEURS DE QUALITE CRC </center></span></u></b>" & "<BR><BR>"
strHtml = strHtml & "<center><img src='cid:QualiteAppels.jpg'></center>" & "<BR><BR>"
strHtml = strHtml & "<center><img src='cid:QualiteEmails.jpg'></center>" & "<BR><BR>"
strHtml = strHtml & "<center><img src='cid:HomogEval.jpg'></center>" & "<BR><BR>"
strHtml = strHtml & "<center><img src='cid:PartCCObj.jpg'></center>" & "<BR><BR>"
'(5)
'Attach pictures in the email and copy it in the email's body (for each picture)
'To put pictures in the email's body, we need to attach them
With objMail.Attachments
.Add nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\KPIAppels.jpg"
.Add nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\KPIEmails.jpg"
.Add nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\DMT.jpg"
.Add nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\FTEProd.jpg"
.Add nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\QualiteAppels.jpg"
.Add nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\QualiteEmails.jpg"
.Add nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\HomogEval.jpg"
.Add nOm & ":\WFM\6. NEW REPORTS\MENSUEL\QUALIPROD CRC\QUALIPROD 2013\img qualiprod\PartCCObj.jpg"
End With
'(6)
'We define the email as HTLM format
'We use the format we created (4)
objMail.HTMLBody = strHtml
objMail.BodyFormat = olFormatHTML
End Sub |
Partager