[VBA] problème envoi mail

Hello la commu'

une idée de pourquoi mon mail ne part pas? erreur à la ligne

Set mail = outlook.CreateItem(olMailItem)
image

mon code

Sub Enreg_VRF()
Dim New_Wbk As Workbook, This_Wbk As Workbook
Dim Sh As Worksheet
Dim LePath As String, LeNom As String
Application.ScreenUpdating = False
Set New_Wbk = Workbooks.Add
Set This_Wbk = ThisWorkbook
For Each Sh In This_Wbk.Worksheets
    If Left(Sh.Name, 2) = "F_" Then
        Sh.Copy After:=New_Wbk.Sheets(Sheets.Count)
    End If
Next Sh
Application.DisplayAlerts = False
LePath = "C:\Users\" & Environ("UserName") & "\Downloads\"
LeNom = Format(Now(), "DD-MMM-YYYY hh mm AMPM") & "_Fichier de construction de nouvelles bulles techniques.xlsx"
With New_Wbk
    .Sheets(1).Delete
    .SaveAs LePath & LeNom
    .Close
End With
'MsgBox "Le fichier de construction a été généré sous " & "C:\Users\" & Environ("UserName") & "\Downloads\"

'envoi de la pièce jointe par email
Dim outlook As outlook.Application
Dim mail As outlook.MailItem

Set mail = outlook.CreateItem(olMailItem)
mail.To = "mail@destinataire"
'mail.CC = ""
'mail.BCC = ""
mail.Subject = "Test macro"
mail.HTMLBody = "Ceci est un message TEST"

fichier = New_Wbk.FullName
mail.Attachments.Add fichier
mail.Send

End Sub

Par avance merci

Bonjour Sitting_bull

Il faut instancier l'application elle même avant le mail

Un tas d'exemple sur ce forum et notamment
https://www.excel-pratique.com/fr/telechargements/utilitaires/pdf-email-vba-excel-no508

A+

Super boulot

Merci

Rechercher des sujets similaires à "vba probleme envoi mail"