Guest User

Untitled

a guest
May 11th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. `Private Sub RemoveRecipientsWhenItemSend(Item As Outlook.MailItem)
  2. Dim RemoveAddrList As VBA.Collection
  3. Dim InfoAddrList As VBA.Collection
  4. Dim Recipients As Outlook.Recipients
  5. Dim aRecipient As Outlook.Recipient
  6. Dim bRecipient As Outlook.Recipient
  7. Dim i
  8. Dim j
  9. Dim a
  10. Dim b
  11. Dim info As Boolean
  12. info = False
  13. Set RemoveAddrList = New VBA.Collection
  14. Set InfoAddrList = New VBA.Collection
  15. InfoAddrList.Add "team@company.com"
  16. RemoveAddrList.Add "member1@company.com"
  17. RemoveAddrList.Add "member2@company.com"
  18. Set Recipients = Item.Recipients
  19. For i = Recipients.Count To 1 Step -1
  20. Set aRecipient = Recipients.Item(i)
  21. For j = 1 To InfoAddrList.Count
  22. If LCase$(aRecipient.Address) = LCase$(InfoAddrList(j)) Then
  23. For a = Recipients.Count To 1 Step -1
  24. Set bRecipient = Recipients.Item(a)
  25. For b = 1 To RemoveAddrList.Count
  26. If LCase$(aRecipient.Address) = LCase$(RemoveAddrList(b)) Then
  27. Recipients.Remove i
  28. Exit For
  29. End If
  30. Next
  31. Next
  32. Exit For
  33. End If
  34. Next
  35. Next
  36.  
  37.  
  38.  
  39.  
  40. End Sub
  41. Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  42. On Error Resume Next
  43. RemoveRecipientsWhenItemSend Item
  44. End Sub
  45. `
  46.  
  47. Option Explicit
  48.  
  49. Private Sub RemoveRecipientsWhenItemSend(Item As Outlook.mailitem)
  50.  
  51. Dim RemoveAddrList As VBA.Collection
  52. Dim InfoAddrList As VBA.Collection
  53.  
  54. Dim Recipients As Outlook.Recipients
  55. Dim aRecipient As Outlook.Recipient
  56. Dim bRecipient As Outlook.Recipient
  57.  
  58. Dim i
  59. Dim j
  60. Dim a
  61. Dim b
  62.  
  63. Dim info As Boolean
  64.  
  65. info = False
  66. Set RemoveAddrList = New VBA.Collection
  67. Set InfoAddrList = New VBA.Collection
  68.  
  69. InfoAddrList.Add "team@company.com"
  70.  
  71. RemoveAddrList.Add "member1@company.com"
  72. RemoveAddrList.Add "member2@company.com"
  73.  
  74. Set Recipients = Item.Recipients
  75.  
  76. For i = Recipients.count To 1 Step -1
  77.  
  78. Set aRecipient = Recipients.Item(i)
  79.  
  80. For j = 1 To InfoAddrList.count
  81.  
  82. Debug.Print LCase$(aRecipient.Address)
  83. Debug.Print LCase$(InfoAddrList(j))
  84.  
  85. If LCase$(aRecipient.Address) = LCase$(InfoAddrList(j)) Then
  86.  
  87. For a = Recipients.count To 1 Step -1
  88.  
  89. 'Set bRecipient = Recipients.Item(a)
  90. Set aRecipient = Recipients.Item(a)
  91.  
  92. For b = 1 To RemoveAddrList.count
  93.  
  94. Debug.Print vbCr & " a: " & a
  95. Debug.Print " LCase$(aRecipient.Address): " & LCase$(aRecipient.Address)
  96. Debug.Print " LCase$(RemoveAddrList(b)): " & LCase$(RemoveAddrList(b))
  97.  
  98. If LCase$(aRecipient.Address) = LCase$(RemoveAddrList(b)) Then
  99. 'Recipients.Remove i
  100. Recipients.Remove a
  101. Exit For
  102. End If
  103.  
  104. Next
  105.  
  106. Next
  107.  
  108. Exit For
  109.  
  110. End If
  111. Next
  112. Next
  113.  
  114. End Sub
  115.  
  116.  
  117. Private Sub RemoveRecipientsWhenItemSend_test()
  118. RemoveRecipientsWhenItemSend ActiveInspector.currentItem
  119. End Sub
  120.  
  121. ' first relsove all recipients per global address book
  122. For Each Recipient In Recipients
  123. Recipient.Resolve
  124. Next
  125.  
  126. For i = Recipients.count To 1 Step -1
  127. For j = Recipients.count To Recipients.count - 1
  128. If Recipients(i) = Recipients(j) Then
  129. Recipients.Remove (i)
  130. End If
  131. Next j
  132. Next i
Add Comment
Please, Sign In to add comment