XL 2010 [RESOLU] Envoi de mails outlook par Excel VBA

jozerebel

XLDnaute Occasionnel
Bonjour le fofo,

J'essaie d'automatiser l'envoi de feuilles transformées en pdf par Outlook via Excel.

J'ai une macro qui fait le job mais à chaque fois Outlook me demande de cliquer pour autoriser l'envoi. Ce qui n'est pas top pour automatiser une tâche, vous en conviendrez.

J'ai cherché un peu sur le net avec des send keys ou autres solutions mais rien ne fonctionne. Comment je peux adapter ma macro pour contourner ce pb ?

D'avance je vous remercie.


Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)

fichier = nom & ".pdf"
Corp = "Bonjour," & _
vbCrLf & vbCrLf & vbCrLf & _
"Message envoyé automatiquement" & _
vbCrLf & vbCrLf & vbCrLf & _
"Ci-joint." & _
vbCrLf & vbCrLf & vbCrLf & _
"Cordialement."

With olMail
.To = AdresseMail
.BCC = ""
.Subject = "" & " - " & titre & " au 24/06/2019"
.Body = Corp
.Display
.Attachments.Add chemin & fichier
.Send


End With
Set olApp = Nothing
Set olMail = Nothing
 

jozerebel

XLDnaute Occasionnel
Bonjour Zebanx, bonjour le Fofo,

Malheureusement, neutraliser le .Display ne contourne pas mon pb.
Cela masque uniquement la fenêtre Outlook mais le message d'avertissement apparaît toujours, m'indiquant qu'un programme tente d'envoyer un mail et je dois, après quelques secondes, cliquer sur Accepter pour envoyer le mail.

Une idée de contournement ?

D'avance merci.
 

zebanx

XLDnaute Accro
Re-
Bonjour Jozerbel

Essayez de rajouter un displayalerts = false dans le code peut-être.

@+

VB:
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)

fichier = nom & ".pdf"
Corp = "Bonjour," & _
vbCrLf & vbCrLf & vbCrLf & _
"Message envoyé automatiquement" & _
vbCrLf & vbCrLf & vbCrLf & _
"Ci-joint." & _
vbCrLf & vbCrLf & vbCrLf & _
"Cordialement."

Application.DisplayAlerts = False

With olMail
.To = AdresseMail
.BCC = ""
.Subject = "" & " - " & titre & " au 24/06/2019"
.Body = Corp
.Display
.Attachments.Add chemin & fichier
.Send

End With
Application.DisplayAlerts = True
Set olApp = Nothing
Set olMail = Nothing
 

jozerebel

XLDnaute Occasionnel
Re-
Bonjour Jozerbel

Essayez de rajouter un displayalerts = false dans le code peut-être.

@+

VB:
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)

fichier = nom & ".pdf"
Corp = "Bonjour," & _
vbCrLf & vbCrLf & vbCrLf & _
"Message envoyé automatiquement" & _
vbCrLf & vbCrLf & vbCrLf & _
"Ci-joint." & _
vbCrLf & vbCrLf & vbCrLf & _
"Cordialement."

Application.DisplayAlerts = False

With olMail
.To = AdresseMail
.BCC = ""
.Subject = "" & " - " & titre & " au 24/06/2019"
.Body = Corp
.Display
.Attachments.Add chemin & fichier
.Send

End With
Application.DisplayAlerts = True
Set olApp = Nothing
Set olMail = Nothing
Malheureusement, toujours le même message d'Outlook....
 

Discussions similaires

Statistiques des forums

Discussions
311 729
Messages
2 081 970
Membres
101 852
dernier inscrit
dthi16088