1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| Sub EnvoiMail()
Dim nomfich As String
Dim nomfich2 As String
Dim Corps As String
Dim Msg, Style, Title, Response, MyString
'Cde_a_emailer = InputBox("Entrez le n° de commande pour lequelle vous voulez envoyer un email", "N° de commande")
'Range("L1").Value = Cde_a_emailer
Cde = InputBox("Entrez le n° de commande pour lequelle vous voulez envoyer un email", "N° de commande")
Range("K1").Value = Cde
'Cde = Range("K1").Value
If Cde = "" Then Exit Sub
Range("K2").Select
Client = ActiveCell.Value
Range("K3").Select
Email = ActiveCell.Value
Range("K4").Select
Date_expe = ActiveCell.Value
Range("K5").Select
Date_expe2 = ActiveCell.Value
Range("K6").Select
Date_Cde = ActiveCell.Value
Range("K7").Select
Date_Cde2 = ActiveCell.Value
ActiveSheet.Range("A1").Select
Msg = "Confirmez vous l'envoi d'un email pour la commande" & vbCrLf & Cde & " du client " & Client
Style = vbYesNo + vbQuestion
Title = "Confirmation envoi email"
Response = MsgBox(Msg, Style, Title) ' Affiche le message.
If Response = vbYes Then ' L'utilisateur a choisi Oui.
myrep = "\\Envoi_BA_par_email\Cde_clé_USB\" & Date_expe
nomfich = myrep & "\" & Cde & ".txt"
nomfich2 = Dir(myrep & "\*" & Cde & "*.txt")
If nomfich2 <> "" Then
Adresse = Email
Sujet = "BULLETINS D'ANALYSE COMMANDE " & Cde
Texte = "Bonjour," & vbCrLf & vbCrLf & "Veuillez trouver ci-joint la liste des produits expédiés le " & Date_expe2 & " et pour laquelle vous pourrez télécharger les bulletins d'analyse sur notre site." & vbCrLf & "Bonne réception." & vbCrLf & "Bien cordialement." & vbCrLf & vbCrLf & "Le Service Commercial"
Shell "C:\Program Files\Outlook Express\msimn.exe " & "/mailurl:mailto:" & _
Adresse & "?subject=" & Sujet & "&Body=" & Texte & ""
SendKeys "%I" & "p" & nomfich & "~"
'Signification des caractères après "SendKeys":
'* %I et P = Insertion de la pièce jointe dans Outlook Express. (%=Alt)
'* ~ = Validation. (~=Entrée)
'* %S = Envoyer.
Else
Msg = "Il n'y a pas de commande n° " & Cde & " expédiée à la date du" & vbCrLf & Date_expe2
Style = vbOK
Title = "Confirmation envoi email"
Response = MsgBox(Msg, Style, Title) ' Affiche le message.
If Response = vbOK Then
Date_Cde = InputBox("Entrez la Date d'expédition de la commande" & vbCrLf & Cde & vbCrLf & vbCrLf & " sous le format : aaaammjj", "Date d'expédition de la commande")
Range("K6").Value = Date_Cde
myrep = "\\Envoi_BA_par_email\Cde_clé_USB\" & Date_Cde
nomfich = myrep & "\" & Cde & ".txt"
nomfich2 = Dir(myrep & "\*" & Cde & "*.txt")
If nomfich2 <> "" Then
Adresse = Email
Sujet = "BULLETINS D'ANALYSE COMMANDE " & Cde
Texte = "Bonjour," & vbCrLf & vbCrLf & "Veuillez trouver ci-joint la liste des produits expédiés le " & Date_Cde2 & " et pour laquelle vous pourrez télécharger les bulletins d'analyse sur notre site." & vbCrLf & "Bonne réception." & vbCrLf & "Bien cordialement." & vbCrLf & vbCrLf & "Le Service Commercial "
Shell "C:\Program Files\Outlook Express\msimn.exe " & "/mailurl:mailto:" & _
Adresse & "?subject=" & Sujet & "&Body=" & Texte & ""
SendKeys "%I" & "p" & nomfich & "~"
'Signification des caractères après "SendKeys":
'* %I et P = Insertion de la pièce jointe dans Outlook Express. (%=Alt)
'* ~ = Validation. (~=Entrée)
'* %S = Envoyer.
Else
Msg = "Il n'y a pas de commande n° " & Cde & " expédiée à la date du" & vbCrLf & Date_Cde2
Style = vbOK
Title = "Confirmation envoi email"
Response = MsgBox(Msg, Style, Title) ' Affiche le message.
End If
End If
End If
End If
ActiveSheet.Range("A1").Select
End Sub |
Partager