.CreationTime ou j.SentOn
.Recipient
j.To
.to
.to
Bonjour à tous,
Je suis entrain d'essayer depuis Excel de récupérer la liste de mail depuis outlook que j'affiche dans un Userform et dans une listview, jusque là tout va bien.
Mon problème est que je souhaite aussi récupérer le nom des pièces jointes, c'est là que je rencontre un soucis car il me récupère bien pour la première ligne le nom de la pièce mais pas pour les suivantes !!!
Voici mon code
VB:Dim OLmail 'As Outlook.MailItem Dim pceJointe As Outlook.Attachment Set olApp = CreateObject("Outlook.Application") Set olns = olApp.GetNamespace("MAPI") Set olxFolder = olns.GetDefaultFolder(6) On Error Resume Next Application.ScreenUpdating = False With ListView1 ImageList1.ListImages.Clear .Gridlines = True .MultiSelect = True ImageList1.ImageHeight = 20 'Hauteur ImageList1.ImageWidth = 20 'Largeur répertoirePhoto = ThisWorkbook.Path c = "mail1" d = "mail2" e = "mail4" ImageList1.ListImages.Add , "Img", LoadPicture(répertoirePhoto & "\" & c & ".JPG") ImageList1.ListImages.Add , "Img2", LoadPicture(répertoirePhoto & "\" & d & ".JPG") ImageList1.ListImages.Add , "Img4", LoadPicture(répertoirePhoto & "\" & e & ".JPG") '------------------------------------------- Set ListView1.SmallIcons = ImageList1 Set ListView1.Icons = ImageList1 '------------------------------------------- Set ListView1.ColumnHeaderIcons = ImageList1 ListView1.CheckBoxes = True With .ColumnHeaders .Clear .Add , , "", 15 .Add , , "Sujet", 150 ', , "Img" .Add , , "Corps", 100 .Add , , "Expéditeur", 90 .Add , , "Date", 60 .Add , , "Pièces jointes", 90 ', , "Img4" End With End With n = 1 Cont1 = 0 Cont2 = 0 For Each i In olxFolder.Items If i.UnRead(n) = True Then ListView1.ListItems.Add ListView1.ListItems(n).ListSubItems.Add , , i.Subject, "Img2" Cont1 = Cont1 + 1 Else ListView1.ListItems.Add ListView1.ListItems(n).ListSubItems.Add , , i.Subject, "Img" Cont2 = Cont2 + 1 End If ListView1.ListItems(n).ListSubItems.Add , , i.Body If i.SenderName = "" Then a = "Inconnu" Else a = i.SenderName End If ListView1.ListItems(n).ListSubItems.Add , , a ListView1.ListItems(n).ListSubItems.Add , , i.CreationTime Set pceJointe = i.Attachments(n) If pceJointe = "" Then b = "Vide" ListView1.ListItems(n).ListSubItems.Add , , b Else b = pceJointe ListView1.ListItems(n).ListSubItems.Add , , b, "Img4" End If Set pceJointe = Nothing Set i.Attachments(n) = Nothing n = n + 1 Next i ListView1.View = lvwReport UserForm1.Label2.Caption = Cont1 UserForm1.Label3.Caption = Cont2 Application.ScreenUpdating = True
Et je vous joint un fichier test.
Merci par avance pour vos aides
Dim olApp As New Outlook.Application 'création objet application Outlook
Dim éléments_envoyés As Outlook.MAPIFolder
Dim OLmail 'As Outlook.MailItem
Dim pceJointe As Outlook.Attachment
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set olxFolder = olNs.GetDefaultFolder(6)
Set éléments_envoyés = olApp.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail)
Add1 = Outlook.Application.Session.Accounts.item(1).SmtpAddress
On Error Resume Next
Application.ScreenUpdating = False
UserForm1.ListView2.ListItems.Clear
With UserForm1.ListView2
.Gridlines = True
.MultiSelect = True
ImageList1.ImageHeight = 20 'Hauteur
ImageList1.ImageWidth = 20 'Largeur
'-------------------------------------------
Set UserForm1.ListView2.SmallIcons = ImageList1
Set UserForm1.ListView2.Icons = ImageList1
'-------------------------------------------
Set UserForm1.ListView2.ColumnHeaderIcons = ImageList1
UserForm1.ListView2.CheckBoxes = True
With .ColumnHeaders
.Clear
.Add , , "", 15
.Add , , "Sujet", 150
.Add , , "P", 15
.Add , , "Corps", 100
.Add , , "Destinataire", 90
.Add , , "Date", 60
.Add , , "Pièces jointes", 90
End With
End With
n = 1
For Each j In éléments_envoyés.Items
UserForm1.ListView2.ListItems.Add
UserForm1.ListView2.ListItems(n).ListSubItems.Add , , j.Subject, "env1"
If j.Importance < Val(2) Then
UserForm1.ListView2.ListItems(n).ListSubItems.Add , , j.Importance
Else
UserForm1.ListView2.ListItems(n).ListSubItems.Add , , j.Importance, "prio"
End If
UserForm1.ListView2.ListItems(n).ListSubItems.Add , , j.Body
a = "test"
UserForm1.ListView2.ListItems(n).ListSubItems.Add , , j.To
UserForm1.ListView2.ListItems(n).ListSubItems.Add , , j.SentOn
' MsgBox i.CreationTime
If Not j.Attachments.Count = 0 Then
For y = 1 To j.Attachments.Count
Set pceJointe = j.Attachments(y)
Next y
End If
Set pceJointe = j.Attachments(n)
If pceJointe = "" Then
b = "Vide"
UserForm1.ListView2.ListItems(n).ListSubItems.Add , , b
Else
b = pceJointe.Filename
UserForm1.ListView2.ListItems(n).ListSubItems.Add , , pceJointe.Filename, "pcj2"
End If
Set pceJointe = Nothing
Set j.Attachments(n) = Nothing
n = n + 1
Next
UserForm1.ListView2.View = lvwReport
Set olApp = Nothing
Application.ScreenUpdating = True
.CreationTime ou j.SentOn
Outlook.Application.Session.Accounts.item(1).SmtpAddress
Le préambule, c'est le pourquoi de la chose?Maintenant je cherche un nouveau challenge ( Si tu as la réponse je suis preneur ) comment depuis Excel simuler " Envoyer/recevoir"