Regueiro
XLDnaute Impliqué
Bonsoir à Tous.
Depuis Excel je veux vérifier sur ma boîte de Reception.
Si il y a des messages Non lu.
Si Ok transférer dans Excel.
Merci de votre aide.
Voici le code :
Merci de Votre Aide.
A+
Depuis Excel je veux vérifier sur ma boîte de Reception.
Si il y a des messages Non lu.
Si Ok transférer dans Excel.
Merci de votre aide.
Voici le code :
HTML:
Option Explicit
Sub Import_Mails_NonLus()
Dim ol As Outlook.Application
Dim olMail As Outlook.MailItem
Dim ns As Namespace
Dim folder As MAPIFolder
Dim ws As Worksheet
Dim i As Integer
Dim strResultat As String
Set ol = CreateObject("Outlook.Application")
Set ns = ol.GetNamespace("MAPI")
'ns.Logon
Set folder = ns.GetDefaultFolder(olFolderInbox)
Set ws = Worksheets("Emails_Non_Lus")
Application.ScreenUpdating = False
'MsgBox ("vous avez mail non lus" & folder.Items.Count)
If folder.Items.Restrict("[UnRead] = True").Count = 0 Then
MsgBox "vous n'avez pas de Message non Lus"
Exit Sub
End If
For Each olMail In folder.Items.Restrict("[UnRead] = True")
If olMail.Attachments.Count <> 0 Then
'For Each olMail In folder.Items.
'If olMail.UnRead = True Then
For i = 1 To folder.Items.Count
With folder.Items
With ws
.Cells(i + 1, 1) = olMail.Subject
.Cells(i + 1, 2) = olMail.To
End With
End With
Next i
End If
Exit For
Next
Set ol = Nothing
Application.ScreenUpdating = True
End Sub
A+