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
| Private Sub Workbook_Open()
'!!! Il faut référencer "Microsoft CDO for Windows 2000 Library" via Tools\References
Dim R As Long, DerLig As Long 'Dimensionnement des variables
Dim Cdo_Message As Object
Set Cdo_Message = CreateObject("CDO.Message")
Set Cdo_Message.Configuration = GetSMTPServerConfig() 'Lance la procédure de configuration
DerLig = Sheets("BDD").Cells(Columns(3).Cells.Count, 3).End(xlUp).Row 'récupère le numéro de la dernière ligne remplie sur base de la colonne C
For R = 3 To DerLig 'Boucle sur chaque ligne depuis la 3ème jusqu'à la dernière (via la variable BerLig)
If Sheets("BDD").Cells(R, 3) = Date And Sheets("BDD").Cells(R, 6) <> "Envoyé" Then
'Envoi le mail via CDO !!! invisible pour l'utilisateur
With Cdo_Message
.To = Sheets("BDD").Cells(R, 5).Value 'Récupère l'adresse du destinataire
'!!!! Adapter la ligne .from avec ton adresse e-mail
.From = "poulain.dominique80@orange.fr" 'ADAPTER avec ton adresse e-mail"
.Subject = "Mail automatique: Rappel"
.HTMLBody = Sheets("BDD").Cells(R, 4) + Cells(R, 1) 'Récupère le message à insérer
.send
End With
Sheets("BDD").Cells(R, 6) = "Envoyé"
End If
Next R 'Passe à la ligne suivante
Set Cdo_Message = Nothing
End Sub
Function GetSMTPServerConfig() As Object
' Microsoft CDO for Windows 2000 Library
Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2
Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Dim Cdo_Config As Object
Set Cdo_Config = CreateObject("CDO.Configuration")
Dim Cdo_Fields As Object
Set Cdo_Fields = Cdo_Config.Fields
With Cdo_Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
'!!!! Adapter l'adresse SMTP, je connais pas Thunderbird, donc difficile de t'indiquer comment la récupérer
.Item(cdoSMTPServer) = "smtp.orange.fr"
.Item(cdoSMTPServerPort) = 25
.Update
End With
Set GetSMTPServerConfig = Cdo_Config
Set Cdo_Config = Nothing
Set Cdo_Fields = Nothing
End Function |
Partager