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
| Private Sub Workbook_Open()
Dim ol As New Outlook.Application
Dim olmail As MailItem, plage As Range
Dim admail As String, cel As Range, j As Long, derlg As Long, nom As String
Dim messMail As String, secours As String, mess As String
With Sheets("feuil1")
derlg = .Range("A" & .Rows.Count).End(xlUp).Row
Set plage = .Range("D2:D" & derlg)
For Each cel In plage
If cel.Offset(0, 2) = "Vrai" Then
If admail = "" Then
admail = cel.Offset(0, 3).Value
nom = cel.Offset(0, -2).Value
Else
admail = admail & ";" & cel.Offset(0, 3).Value
nom = nom & Chr(13) & cel.Offset(0, -2).Value
End If
End If
If admail <> "" Then
mess = MsgBox("les personnes suivantes : " & Chr(13) & nom & Chr(13) & " ne sont pas à jour" & Chr(13) _
& "Voulez-vous envoyer la relance?", vbOKCancel)
If mess = 1 Then
admail = InputBox("destinataire", , admail)
'For j = 1 To 2
messMail = "Hello," & Chr(10) & Chr(10) & "For your information, loan no. " & cel.Offset(0, -1).Value _
& cel.Offset(0, -2) & "will end on" & cel.Offset(0, 1).Value _
& Chr(10) & Chr(10) & "Thanks a lot for your prompt action." & Chr(10) & Chr(10) & "Kind regards," _
& Chr(10) & Chr(10) & Chr(10) & "Marie"
On Error Resume Next
Shell """C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE"""
Set ol = New Outlook.Application
Set olmail = ol.CreateItem(olMailItem)
'If Err Then
'secours = MsgBox("Problème avec le serveur de messagerie, Envoyer en direct ?", vbOKCancel)
'If secours = 1 Then
'Call mail_direct: Exit Sub
'Else
'Exit Sub
'End If
'Else
With olmail
.To = admail
.Subject = "Info. Return loan order" 'Sujet
.Body = messMail 'Corps du mail
.Send '.Display 'On peut switcher entre .send et .display selon que l'on veut envoyer le mail (send) ou seulement le préparer et le vérifier(display)
End With
On Error GoTo 0
'End If
'Next j
End If
Else
End If
Next cel
End With
End Sub |