Bonjour,
Je souhaite rechercher des mails dans ma boite aux lettres à partir d'Excel en utilisant la fonction AdvancedSearch.
Vu sur le site de MSDN, le code fourni est le suivant :
Pour l'utiliser sous Excel, j'ai adapter le code comme ci_dessous :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 Public blnSearchComp As Boolean Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search) MsgBox "The AdvancedSearchComplete Event fired." blnSearchComp = True End SubSub TestAdvancedSearchComplete() Dim sch As Outlook.Search Dim rsts As Outlook.Results Dim i As Integer blnSearchComp = False Const strF As String = "urn:schemas:mailheader:subject = 'Test'" Const strS As String = "Inbox" Set sch = Application.AdvancedSearch(strS, strF) While blnSearchComp = False DoEvents Wend Set rsts = sch.Results For i = 1 To rsts.Count MsgBox rsts.Item(i).SenderName Next End Sub
Si cet essai fonctionne correctement sous Outlook, ce n'est pas le cas sous Excel. J'obtiens bien le message "The AdvancedSearchComplete Event fired" mais ensuite le programme tourne sans arrêt.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Public blnSearchComp As Boolean Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search) MsgBox "The AdvancedSearchComplete Event fired" blnSearchComp = True End Sub Sub TestAdvancedSearchComplete() Dim olApp As Outlook.Application Dim olNameSpace As Outlook.Namespace Dim olDossier As Outlook.MAPIFolder Dim sch As Outlook.Search Dim rsts As Outlook.Results Dim i As Integer blnSearchComp = False Const strF As String = "urn:schemas:mailheader:subject = 'test'" Const strS As String = "Inbox" Set olApp = CreateObject("Outlook.Application") Set sch = olApp.AdvancedSearch(strS, strF) While blnSearchComp = False DoEvents Wend Set rsts = sch.Results For i = 1 To rsts.Count MsgBox rsts.Item(i).SenderName Next End Sub
Quelqu'un peut-il m'aider ?
Merci d'avance.
Partager