Bonjour,
J'essaye de créer un code VBA pour envoyer un fichier excel en piece jointe d'un mail.
J'ai toujours une erreur sur mon .Attachments.Add ... comment mettre le chemin ou se trouve le fichier ?
Voici le code :
Merci pour votre aide !
'Envoi d'un email
Sub Envoyer_Mail_Outlook()
Dim ObjOutlook As New Outlook.Application
Dim oBjMail
Dim Nom_Fichier As String
Sheets("Formulaire_demandeur").Select
Cells(64, 2).Select
adr_dest = Selection.Value
'Sheets("Demande").Select
'Cells(62, 11).Select
'pj = Selection.Value
Set ObjOutlook = New Outlook.Application
Set oBjMail = ObjOutlook.CreateItem(olMailItem)
'---------------------------------------------------------
'Exemple pour envoyer un classeur en pièce jointe
'Nom_Fichier = Application.GetOpenFilename("Fichier excel (*.xls;*.xlsx;*.xlsm), *.xls;*.xlsx;*.xlsm")
'If Nom_Fichier = "Faux" Then Exit Sub
'---------------------------------------------------------
'Ou bien entrer le path et nom du fichier autrement
'Nom_Fichier = ActiveWorkbook
'If Nom_Fichier = "" Then Exit Sub
'---------------------------------------------------------
With oBjMail
.To = adr_dest '"xxx@xxx.com" ' le destinataire"
.Subject = "Ici c'est l'objet" ' l'objet du mail
.Body = "Ici le texte du mail " 'le corps du mail ..son contenu
.Attachments.Add pj '"C:\Data\essai.txt" ' ou Nomfichier
.send
End With
'ObjOutlook.Quit
Set oBjMail = Nothing
Set ObjOutlook = Nothing
End Sub