Sub SendMail1_Outlook()
'Avant de lancer cette macro, Dans l'éditeur VBA: Faire Menu / Tools / Reference / Cocher "Microsoft Outlook Library"
Dim ligne As Long
Dim ol As New Outlook.Application
Dim olmail As MailItem
Dim CurrFile As String
On Error Resume Next
ligne = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
If ligne = 0 Then
MsgBox "Une erreur est survenue lors de la récupération du numéro de ligne" & vbCrLf & "Essayez de recommencer", vbInformation, "SendMail"
Exit Sub
End If
On Error GoTo 0
If Range("M" & ligne).Value = "Provision insuffisante" Then
Set ol = New Outlook.Application
Set olmail = ol.CreateItem(olMailItem)
With olmail
.To = Range("J" & ligne).Value
.CC = Range("L" & ligne).Value
.Subject = "Impayé - Demande de Blocage" & " " & "-" & " " & Range("C" & ligne).Value & " " & Range("D" & ligne).Value
.Body = Range("I" & ligne).Value & Chr(10) & Chr(10) & "Merci de bien vouloir bloquer ce compte suite à la traite du" & " " & Range("B" & ligne).Value & " " & "revenue impayée pour motif Provision Insuffisante." & Chr(10) & Chr(10) & "Cordialement"
.Attachments.Add "C:\Users\Shadoz\Desktop\1.txt"
.Display '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
Else
Rep = MsgBox("Le motif de l'impayé ne permet pas de faire le blocage automatique. Merci de faire la demande manuellement.", vbCritical, "Service Comptabilité")
End If
End Sub