XL 2010 Copie un mail via macro

Bens7

XLDnaute Impliqué
Bonjour à tous !
Voilà après plusieurs jours de recherche infructueuse je vous explique mon souhait:
Je souhaiterais un macro en étant sur Excel qui copie le dernier email (Outlook 2010) reçu de : "nomduclient@hotmail.com" présent dans ma boîte de réception (Account 1) > Dans le dossier "C://dossier/test/"

Voilà !
Merci à vous !
 
Dernière édition:

Bens7

XLDnaute Impliqué
Re bonjour
J'ai supprimer mon dernier post...

Ce fichier excel est juste pour expliquer ce que j'ai besoin de faire :
- Sur la droite (imagine que c'est ma boîte mail Outlook).
- Au milieu : (imagine que c'est le dossier du client sur mon DD)
- À droite (imagine que c'est mon fichier excel)

1) Depuis mon fichier excel : Je met manuellement l'adresse email voulu et le chemin du dossier voulu.
2) Je clik
3) Le mail le plus récent voulu va dans le dossier que j'ai renseigné précédemment dans le USER.

Je ne voie pas comment être plus clair...merxi
 

Staple1600

XLDnaute Barbatruc
Re

Merci.

Pour suivre ton idée, peux-tu tester cette macro de test
à partir d'Excel (en ayant Outlook ouvert mais en réduction)
NB: Cocher la référence à la librairie Outlook dans VBE
VB:
Sub Test()
Dim olApp As Outlook.Application
Dim olNs As Outlook.Namespace
Dim olFld As Outlook.MAPIFolder
Dim objMail As Object

Set olApp = Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set olFld = olNs.GetDefaultFolder(olFolderInbox)

olFld.items.Sort "Received", False
Set objMail = olFld.items.GetLast ' Outlook 2010

If TypeOf objMail Is MailItem Then
' mettre une adresse mail réelle
    If objMail.SenderEmailAddress = "toto@titi.fr" Then
    ' suite code VBA
    'ici ligne pour test
    MsgBox objMail.Subject
    End If
End If
Set objMail = Nothing
Set olFld = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub
 

Staple1600

XLDnaute Barbatruc
Re

Tu as bien coché la référence à Outlook dans VBE?
(voir message#17)

Comme je ne pas tester ce soir
(Je n'ai Outlook qu'au boulot)
il faudrait qu'un autre membre du forum avec Outlook fasse le test

Sinon faudra attendre demain que je teste au boulot.
 

Staple1600

XLDnaute Barbatruc
Re

Bon alors, fais ce 2ième test (juste pour voir si il n'y apas d'erreur)
VB:
Sub Test2()
Dim olApp As Outlook.Application
Dim olNamespace As Outlook.Namespace
Dim olItem As MailItem
Dim rngOut As Range
Dim olInbox As Outlook.MAPIFolder
Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
Set rngOut = Cells(1, 1)
Set olInbox = olNamespace.GetDefaultFolder(olFolderInbox)
For Each olItem In olInbox.Items
    rngOut = olItem.Subject
    Set rngOut = rngOut.Offset(1, 0)
Next
Set rngOut = Nothing
Set olInbox = Nothing
Set olNamespace = Nothing
Set olApp = Nothing
End Sub
 

Staple1600

XLDnaute Barbatruc
Re

Normalement cela devrait lister tes mails dans la feuille active du classeur où est la macro
Et si on ajoute ce test, il se passe toujours rien ??
VB:
Sub Test3()
Dim olApp As Outlook.Application
Dim olNamespace As Outlook.Namespace
Dim olItem As MailItem
Dim rngOut As Range
Dim olInbox As Outlook.MAPIFolder
Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
Set rngOut = Cells(1, 1)
Set olInbox = olNamespace.GetDefaultFolder(olFolderInbox)
For Each olItem In olInbox.Items
MsgBox olItem.Subject' ajout
    rngOut = olItem.Subject
   Set rngOut = rngOut.Offset(1, 0)
Next
Set rngOut = Nothing
Set olInbox = Nothing
Set olNamespace = Nothing
Set olApp = Nothing
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 104
Messages
2 085 345
Membres
102 868
dernier inscrit
JJV