Bonjour à tous,

J'ai un soucis sur un code. En effet, lorsque je reçois un mail une macro s'exécute. Si un second mail arrive dans la foulée (lorsque la macro est en court d'exécution) il ne déclenchera pas la macro et ce malgrès un : "For Each olMail In olItms"

De ce fait, à la fin de la macro j'ai placé un (je vous entends crier ) goto. Celui ci renvoi au début de la macro.
Jusque là tout fonctionne.

Cette macro ouvre un classeur Excel composé de trois macros.
C'est sur la macro "Envoyer_Mail_Outlook" que j'ai une erreur lors du traitement du second mail et très certainement des suivants.

Je vous mets cette macro : et surligne là où la macro s'arrête en rouge

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Sub Envoyer_Mail_Outlook()
Dim ObjOutlook As New Outlook.Application
Dim oBjMail
Dim Nom_Fichier1 As String
Dim Nom_Fichier2 As String
Dim Nom_Fichier3 As String
Dim Nom_Fichier4 As String
Dim Fichier_Prendre As String

Dim nomfichier As String
Dim Cheminfichier As String

nom = ActiveSheet.Range("E8")
chemin = "F:\xx"

   Set ObjOutlook = New Outlook.Application ( 80010100 échec d'appel système)
   Set oBjMail = ObjOutlook.CreateItem(olMailItem)

  Nom_Fichier1 = chemin & nom & ".pdf"
  Nom_Fichier2 = chemin & nom & ".pdf"
  Nom_Fichier3 = chemin & nom & ".pdf"
  Nom_Fichier4 = chemin & nom & ".pdf"
  If Nom_fichier = "Faux" Then Exit Sub

 With oBjMail
       .To = ActiveSheet.Range("F9").Value 
       .Subject = "XXXXX" & Date & ""         ' l'objet du mail
       .Body = "(Message automatique, ne pas répondre) "
       .Attachments.Add Nom_Fichier1
       .Attachments.Add Nom_Fichier2
       .Display
       .Send

    End With
    
    Set oBjMail = Nothing
    Set ObjOutlook = Nothing
    
    Set oBjMail = ObjOutlook.CreateItem(olMailItem)
    
         With oBjMail
       .To = ActiveSheet.Range("F9").Value  
       .Subject = "XXXXX" & Date & "         ' l'objet du mail
       .Body = "(Message automatique, ne pas répondre)"
       .Attachments.Add Nom_Fichier4
       .Display
       .Send
    End With
    Set oBjMail = Nothing
    Set ObjOutlook = Nothing


ThisWorkbook.Saved = True
excel.Application.Quit

  Set ObjOutlook = Nothing
  Set oBjMail = Nothing

End Sub

Je n'arrive pas à comprendre pourquoi j'ai ce soucis uniquement sur le second passage alors qu'à la première passe il y a bien deux envoi de mail qui se passe correctement et en fin de macro je note bien :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
Set ObjOutlook = Nothing
Set oBjMail = Nothing
Si vous pouvez m'aider car je suis en pleine galère.

Merci d'avance
Axel