Macro excel envoi mail avec fichier joint
Résolu
Utilisateur anonyme
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonjour,
J'aimerai envoyer automatiquement une feuille d'un fichier Excel via Outlook.
J'utilise la macro suivante que j'ai récupérée d'une autre discussion.
Sub SendMail()
' Copy the sheet(1)
ThisWorkbook.Sheets(1).Copy
' Send Email
With ActiveWorkbook
.SendMail Recipients:=Array("toto@ss.ch", "xxx@sss.ch"), Subject:="Test" & Format(Date, "dd/mmm/yy")
.Close SaveChanges:=False
End With
J'ai une liste de destinataire qui varie selon la feuille, j'ai donc essayé de modifier cette macro ainsi sachant que l'email du destinataire est inscrit sur la feuille 1 cellule M1 :
Function SendMail()
Dim y As String
Dim x As Integer
y = Sheets(1).Range("M1").Value
x = Sheets(1).Range("K1").Value
' Copy the sheet(1)
ThisWorkbook.Sheets(x).Copy
' Send Email
With ActiveWorkbook
.SendMail Recipients:="y", Subject:="test" & Format(Date, "dd/mmm/yy")
.Close SaveChanges:=False
End With
' Subject:=Range("Feuil1!B1").Value & " " & Range("Feuil1!A1").Value
End Function
Mais ça ne marche pas...
Pourriez-vous m'indiquer ce que je dois modifier s'il vous plaît.
Merci d'avance.
Elsie
J'aimerai envoyer automatiquement une feuille d'un fichier Excel via Outlook.
J'utilise la macro suivante que j'ai récupérée d'une autre discussion.
Sub SendMail()
' Copy the sheet(1)
ThisWorkbook.Sheets(1).Copy
' Send Email
With ActiveWorkbook
.SendMail Recipients:=Array("toto@ss.ch", "xxx@sss.ch"), Subject:="Test" & Format(Date, "dd/mmm/yy")
.Close SaveChanges:=False
End With
J'ai une liste de destinataire qui varie selon la feuille, j'ai donc essayé de modifier cette macro ainsi sachant que l'email du destinataire est inscrit sur la feuille 1 cellule M1 :
Function SendMail()
Dim y As String
Dim x As Integer
y = Sheets(1).Range("M1").Value
x = Sheets(1).Range("K1").Value
' Copy the sheet(1)
ThisWorkbook.Sheets(x).Copy
' Send Email
With ActiveWorkbook
.SendMail Recipients:="y", Subject:="test" & Format(Date, "dd/mmm/yy")
.Close SaveChanges:=False
End With
' Subject:=Range("Feuil1!B1").Value & " " & Range("Feuil1!A1").Value
End Function
Mais ça ne marche pas...
Pourriez-vous m'indiquer ce que je dois modifier s'il vous plaît.
Merci d'avance.
Elsie
A voir également:
- Vba envoyer mail avec pièce jointe
- Mail delivery system - Astuces et Solutions
- Pièce d'identité - Accueil - Services publics
- Gmail envoyer un mail - Guide
- Messenger impossible d'envoyer en jaune - Forum Facebook Messenger
- Je n'arrive pas a envoyer un mail avec piece jointe gmail ✓ - Forum Mail
4 réponses
Bonjour,
Cette macro marche parfaitement, j'ai du faire une erreur hier.
Private Sub Bouton6_QuandClic()
Dim y, chemin, nom As String
Dim x As Integer
Dim ol As Object, myItem As Object
chemin = ActiveWorkbook.Path
y = Sheets(1).Range("M1").Value
x = Sheets(1).Range("K1").Value
nom = "contrôle " & Sheets(x).Name
ThisWorkbook.Sheets(x).Copy
ActiveWorkbook.SaveAs chemin & "\" & nom
Set ol = CreateObject("outlook.application")
Set myItem = ol.CreateItem(olMailItem)
myItem.To = y
myItem.Subject = "envoi d'un fichier attaché"
myItem.Body = "Bonjour, " & Chr(10) & "Vous trouverez ci-joint le tableau de Contrôle pour votre service. " & Chr(10) & "Merci de bien vouloir me faire un retour avec vos corrections. " & Chr(10) & "Cordialement, " & Chr(10) & "Elsie "
myItem.Attachments.Add ActiveWorkbook.FullName
myItem.Send
Set ol = Nothing
ActiveWorkbook.Close
End Sub
Merci beaucoup pour ton aide !!
Elsie
Cette macro marche parfaitement, j'ai du faire une erreur hier.
Private Sub Bouton6_QuandClic()
Dim y, chemin, nom As String
Dim x As Integer
Dim ol As Object, myItem As Object
chemin = ActiveWorkbook.Path
y = Sheets(1).Range("M1").Value
x = Sheets(1).Range("K1").Value
nom = "contrôle " & Sheets(x).Name
ThisWorkbook.Sheets(x).Copy
ActiveWorkbook.SaveAs chemin & "\" & nom
Set ol = CreateObject("outlook.application")
Set myItem = ol.CreateItem(olMailItem)
myItem.To = y
myItem.Subject = "envoi d'un fichier attaché"
myItem.Body = "Bonjour, " & Chr(10) & "Vous trouverez ci-joint le tableau de Contrôle pour votre service. " & Chr(10) & "Merci de bien vouloir me faire un retour avec vos corrections. " & Chr(10) & "Cordialement, " & Chr(10) & "Elsie "
myItem.Attachments.Add ActiveWorkbook.FullName
myItem.Send
Set ol = Nothing
ActiveWorkbook.Close
End Sub
Merci beaucoup pour ton aide !!
Elsie