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
| Public Sub Ta_Fonction()
Dim MailUser As String
Dim MailDestinataire As String
Dim MailCopie As String
Dim i As Integer
'Variable paramètrage Serveur d'envoi
Dim MAIL_FROM As String
Dim MAIL_SMTP_SERVER As String
Dim MAIL_SMTP_SERVERPORT As String
MailUser = Sheets("Param Mail").Range("B5")
MailDestinataire = ""
MailCopie = ""
'Paramètrage serveur
MAIL_FROM = Sheets("Param Mail").Range("B5").Value 'Adresse mail de l'utilisateur de Réactualisation Délai
MAIL_SMTP_SERVER = Sheets("Param Mail").Range("B2").Value 'Adresse du serveur SMTP
MAIL_SMTP_SERVERPORT = Sheets("Param Mail").Range("B3").Value 'Port SMTP
'Liste des destinataires
i = 2
While Sheets("Param Mail").Range("E" & i) > ""
MailDestinataire = MailDestinataire & Sheets("Param Mail").Range("E" & i) & ","
i = i + 1
Wend
MailDestinataire = Left(MailDestinataire, Len(MailDestinataire) - 1) 'On enlève la dernière virgule
i = 2
'Liste des copies
While Sheets("Param Mail").Range("H" & i) > ""
MailCopie = MailCopie & Sheets("Param Mail").Range("H" & i) & ","
i = i + 1
Wend
'Au moins une copie
If Len(MailCopie) > 1 Then
MailCopie = Left(MailCopie, Len(MailCopie) - 1) 'On enlève la dernière virgule
End If
' 'Demande ajout fichier pour pièce jointe
' '----------------------------------------------------------------------------
' Dim fd As FileDialog
' Dim NameFile As String
' Set fd = Application.FileDialog(msoFileDialogFilePicker)
'
' Dim vrtSelectedItem As Variant
'
' With fd
' If .Show = -1 Then
' For Each vrtSelectedItem In .SelectedItems
'
' 'Vérif fichier Excel
' If Right(vrtSelectedItem, 4) <> ".xls" And Right(vrtSelectedItem, 4) <> "xlsx" And Right(vrtSelectedItem, 4) <> "XLSX" And Right(vrtSelectedItem, 4) <> ".XLS" And Right(vrtSelectedItem, 4) <> "xlsm" And Right(vrtSelectedItem, 4) <> "XLSM" Then
' MsgBox "Erreur : Vous n'avez pas sélectionné un Excel. ", vbCritical
' Else
'
' NameFile = vrtSelectedItem
' End If
' Next vrtSelectedItem
' 'The user pressed Cancel.
' Else
' Exit Sub
' End If
' End With
'----------------------------------------------------------------------------
'Vérification de l'intitulé du mail
If MsgBox("L'intitulé du mail sera : ""Résultat analyse " & DateDKP & """ Envoyer?", vbYesNo) = vbYes Then
Call SMTPSendMail(MailDestinataire, MailCopie, MAIL_FROM, MAIL_SMTP_SERVER, MAIL_SMTP_SERVERPORT)
End If
End Sub |
Partager