En complément à mon précédent message:
Voici le code qui se plante lorsque excel est lancé en batch et ne se plante pas si excel est lancé normalement via un double clic.
Une instance "Outlook" est déjà ouverte lorsque ce code s'exécute.
'Il faut activer la référence "Microsoft Outlook Library" Avant de lancer cette macro,
' Dans l'éditeur VBA: Faire Menu / Tools / Reference / Cocher "Microsoft Outlook Library"
Sub Envoyer_Mail_Outlook(Nom_Fichier, nom_fichierpdf, nmailx)
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object
Dim S As Shape
Dim sNomFic As String, sRep As String, WshShell As Object
Dim Dest As String
Dim CheminDossier As String
Application.ScreenUpdating = False
Dest = nmailx
CheminDossier = "C:\CVS\Plannings\"
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Envoi du mail
Set OutApp = CreateObject("outlook.application")
Set OutMail = OutApp.CreateItem(0) ' PLANTAGE ICI en batch
If Nom_Fichier = "" Then Exit Sub
With OutMail
.To = Dest
.CC = "" 'Renseigner une adresse, si vous voulez une copie conforme
.Body = messag2
.Attachments.Add Nom_Fichier
.Subject = messag1
.Display
.Send
End With
Set OutApp = Nothing
Set OutMail = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With