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
| Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'---------------------------------------------------------------------------------------
' Procedure : Application_ItemSend
' Author : OCTU
' Date : 08/03/2016
' Purpose : Envoi d'une PJ et destinataire CC Selon le sujet
'---------------------------------------------------------------------------------------
'
Dim pj
Dim MyRecipientCC As Recipient, CC
Dim att As Attachment, rec As Recipient
Dim tFileName
Dim PjExiste As Boolean
Dim CCExiste As Boolean
Dim m_Mail As Outlook.MailItem
Dim Confirmation
pj = "C:\Users\Comptabilité\Documents\joindredoc.pdf"
'pj = "C:\temp\monpdf.pdf"
CC = "titi@toto.com"
If Item.Class = olMail Then
Set m_Mail = Item
'ICI on test le sujet et on fait les ACTIONS
If InStr(1, m_Mail.Subject, "SOUMISSION", vbTextCompare) Then 'non sensible à la casse
'if instr(0, m_Mail.Subject,"SOUMISSION",vbBinaryCompare) then 'sensible à la casse
If Dir(pj) <> "" Then
PjExiste = False
tFileName = Split(pj, "\", , vbBinaryCompare)
For Each att In m_Mail.Attachments
If UCase(att.FileName) = UCase(tFileName(UBound(tFileName))) Then
PjExiste = True
Exit For
End If
Next
If Not PjExiste Then m_Mail.Attachments.Add pj
End If
CCExiste = False
For Each rec In m_Mail.Recipients
If LCase(GetSMTPAddressForRecipient(rec)) = LCase(CC) Then
CCExiste = True
Exit For
End If
Next
If Not CCExiste Then
Set MyRecipientCC = m_Mail.Recipients.Add(CC)
MyRecipientCC.Type = olCC
MyRecipientCC.Resolve
End If
Confirmation = MsgBox("Etes-vous sûrs ?", vbQuestion + vbYesNo, "Envoi avec SOUMISSION")
If Confirmation = vbNo Then Cancel = True
End If
End If
End Sub |
Partager