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
|
Public WithEvents m_objMail As Outlook.mailItem
Sub Application_ItemLoad(ByVal Item As Object)
On Error Resume Next
Dim strClass As String
Select Case Item.Class
Case olMail
Set m_objMail = Item
End Select
End Sub
Sub m_objMail_Open(Cancel As Boolean)
If m_objMail.UnRead Then
Dim olkMsg As Object, _
excApp As Object, _
excWkb As Object, _
excWks As Object, _
intRow As Integer, _
intVersion As Integer, _
strFilename As String, _
sender As String
strFilename = "C:\Temp\Test.xlsx"
If strFilename <> "" Then
intVersion = GetOutlookVersion()
Set excApp = CreateObject("Excel.Application")
If FileExists(strFilename) Then
Set excWkb = excApp.Workbooks.Open(strFilename)
Set excWks = excWkb.ActiveSheet
Else
excApp.SheetsInNewWorkbook = 1
Set excWkb = excApp.Workbooks.Add
excWkb.SaveAs (strFilename)
MsgBox ("Le fichier a été créé sur " + strFilename)
excWkb.WorkSheets(1).Name = "Mail"
Set excWks = excWkb.ActiveSheet
With excWks
.Cells(1, 1) = "Expéditeur"
.Cells(1, 2) = "Objet"
.Cells(1, 3) = "Date de récéption"
.Cells(1, 4) = "Date d'ouverture"
End With
End If
excWks.Rows(2).Insert
sender = GetSMTPAddress(m_objMail, intVersion)
excWks.Cells(2, 1) = sender
excWks.Cells(2, 2) = m_objMail.Subject
excWks.Cells(2, 3) = m_objMail.ReceivedTime
excWks.Cells(2, 4) = Date + Time
excWkb.Close (True)
End If
Set excWks = Nothing
Set excWkb = Nothing
excApp.Quit
Set excApp = Nothing
MsgBox ("Le mail de " + sender + " a été exporté avec succès")
End If
End Sub |
Partager