Option Explicit
'
' Listing 11.6. A procedure that reads Inbox data into a worksheet.
'
Sub ReadInboxData()'Sub LireMailsObjets()
Dim ol As Outlook.Application
Dim ns As NameSpace
Dim folder As MAPIFolder
Dim ws As Worksheet
Dim i As Integer
'
' Establish a connection and log on
'
Set ol = CreateObject("Outlook.Application")
Set ns = ol.GetNamespace("MAPI")
ns.Logon
'
' Get the default Inbox folder and set Receive Mail worksheet
'
Set folder = ns.GetDefaultFolder(olFolderInbox)
'+++++++++++' modifs
Set folder =ns.GetDefaultFolder(olFolderSentMail)
'+++++++++++
'+++++++++++ 'modifs
Set ws = Worksheets("Emails reçus"")
'il faut qu'il y ait une fuille avec ce nom
'ou alors adapter avec le nom de ton choix
'++++++++++
'Set ws = Worksheets("Receive Mail")
'
' Run through each item in the Inbox
'
For i = 1 To folder.Items.Count
With folder.Items(i)
'
' Record the sender, subject, size,
' received time, and some of the body
'
ws.[A1].Offset(i, 0) = .SenderName
ws.[A1].Offset(i, 1) = .SenderEmailAddress
ws.[A1].Offset(i, 2) = .Subject
ws.[A1].Offset(i, 3) = .Size
ws.[A1].Offset(i, 4) = .ReceivedTime
ws.[A1].Offset(i, 5) = Left(.Body, 100)
End With
Next 'i
'
' Log off the session
'
ns.Logoff
Set ol = Nothing
End Sub