Envoyer un mail avec Excel

Bonjour à toutes et à tous ,

J'ai récupérer sur internet la macro ci-dessous qui me permet d'envoyer un mail dans Excel avec une pièce jointe (grand merci à son créateur).

Étant ignorant des subtilités du VBA pour Excel , je ne sais pas comment faire pour envoyer une plage de cellules (en l'occurrence A7:G34) au lieu de simplement la cellule A7 comme dans la macro.

Remplacer "A7" par "A7:G34" me renvoie le message : "erreur exécution 13". Ça aurait été trop beau...

J'ai parcouru le net mais sans trouver jusqu'alors mon bonheur.

Alors si quelqu'un pouvait me venir en aide ...

Merci d'avance

Sub essai()
Dim Subj As String
Dim EmailAddr As String
Dim Fichier As String
Dim Msg As String
Dim HLink As String
'-------------------------------------------------définir les données
Subj = Range("b4")
EmailAddr = Range("b1")
Fichier = "k:\Jean-Marie\pdf\caf.pdf"

'--------------------------------------------------Composer le message
Msg = Msg & Range("a7") '--------------------------------------------------Construire lien hypertexte
HLink = "mailto:" & EmailAddr & "?"
HLink = HLink & "subject=" & Subj & "&"
HLink = HLink & "body=" & Msg
'--------------------------------------------------Transmettre le message
ActiveWorkbook.FollowHyperlink HLink
Application.Wait (Now + TimeValue("0:00:03"))
SendKeys "%i", True
Application.Wait (Now + TimeValue("0:00:03"))
SendKeys "p", True
Application.Wait (Now + TimeValue("0:00:03"))
SendKeys Fichier, True
Application.Wait (Now + TimeValue("0:00:03"))
SendKeys "{enter}", True
Application.Wait (Now + TimeValue("0:00:03"))
SendKeys "%s", True
End Sub

Salut le forum

Utilise les balises Code, c'est plus lisible

Sub essai() 
Dim Subj As String 
Dim EmailAddr As String 
Dim Fichier As String 
Dim Msg As String 
Dim HLink As String 
'-------------------------------------------------définir les données 
Subj = Range("b4") 
EmailAddr = Range("b1") 
Fichier = "k:\Jean-Marie\pdf\caf.pdf" 

'--------------------------------------------------Composer le message 
Msg = Msg & Range("a7") '--------------------------------------------------Construire lien hypertexte 
HLink = "mailto:" & EmailAddr & "?" 
HLink = HLink & "subject=" & Subj & "&" 
HLink = HLink & "body=" & Msg 
'--------------------------------------------------Transmettre le message 
ActiveWorkbook.FollowHyperlink HLink 
Application.Wait (Now + TimeValue("0:00:03")) 
SendKeys "%i", True 
Application.Wait (Now + TimeValue("0:00:03")) 
SendKeys "p", True 
Application.Wait (Now + TimeValue("0:00:03")) 
SendKeys Fichier, True 
Application.Wait (Now + TimeValue("0:00:03")) 
SendKeys "{enter}", True 
Application.Wait (Now + TimeValue("0:00:03")) 
SendKeys "%s", True 
End Sub

Merci j'y penserais à l'avenir.

Sinon, tu n'as pas une idée pour mon problème ?

Rechercher des sujets similaires à "envoyer mail"