Créer une boucle pour envoyer en un seul click mes commandes
Bonjour,
Sur le fichier en PJ, j ai fait une macro qui me permet d’envoyer en automatique un mail lorsque je Click sur « ENVOI Destinataire ». Les infos envoyées sont celles qui figurent dans l’onglet »Commande » de mon fichier qui lui-même est alimenté par un onglet « Source ».
Chaque ligne de l’onglet « Source » permet d’envoyer une nouvelle commande à chaque fois.
Je souhaiterais ainsi réaliser une boucle qui me permette d’envoyer en une seule fois toutes mes commandes d’un coup quand je Click sur « ENVOI Destinataire » et éviter ainsi de devoir passer manuellement à la ligne suivante à chaque fois.
Je n’arrive pas à créer une telle boucle, pourriez vous m’aider à y parvenir
Merci par avance
Cdt
Py
Bonjour,
Tu peux tester le code suivant ....
Je ne sais pas si tu es l'auteur de la macro ... mais ...
J'ai l'impression que quelqu'un a quelque peu modifié les dfférents éléments ... car les plages ne correspondent pas à leur localisation dans les feuilles ...
Option Explicit
Sub Send_Range_Or_Whole_Worksheet_with_MailEnvelope()
'Working in Excel 2002-2016
Dim wks1 As Worksheet
Dim wks2 As Worksheet
Dim Sendrng As Range
Dim rng1 As Range
Dim c As Range
Dim lastr As Long
On Error GoTo StopMacro
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Define the worksheets
Set wks1 = Feuil1 ' Source
Set wks2 = Feuil2 ' Commande
' Determine last Row in first sheet
lastr = wks1.Cells(Application.Rows.Count, "A").End(xlUp).Row
' Define the Source range
Set rng1 = wks1.Range("A3:A" & lastr)
' Start Loop
For Each c In rng1
' copy each N° de Commande from first sheet to second sheet
c.Copy Destination:=wks2.Range("C2")
'Fill in the Range you want to mail
'Note: please check if the range is the exact one ...
Set Sendrng = wks2.Range("A1:H39")
With Sendrng
' Create the mail and send it
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
' Set the optional introduction field thats adds
' some header text to the email body.
.Introduction = ""
With .Item
While .Attachments.Count > 0
.Attachments.Remove 1
Wend
.To = Range("C17")
.CC = ""
.BCC = ""
.Subject = Range("C2")
.SentOnBehalfOfName = "cmi.gestre@socgen.com"
.Attachments.Add ("V:\GTPS\GFL\SCG-PCM-IMP\PRO_C\Facturation Token - En construction\3S Key facturation via Perla.pdf")
.Send
End With
End With
End With
Next c
StopMacro:
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
ActiveWorkbook.EnvelopeVisible = False
End SubJ'espère que cela pourra t'aider ...
Bonjour,
Merci pour votre retour rapide;
J'ai essayé votre code avec 4 lignes mais il semble que la macro tourne sans s'arrêter , au bout de quelques minutes je dois fermer le fichier Excel.
Sauriez vous d'où cela peut il venir?
Merci
Cdt
Py
Re,
Désolé ... je n'ai pas les moyens de faire de test ...