Guest User

Untitled

a guest
Jun 24th, 2018
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  2. Dim recips As Outlook.Recipients
  3. Dim recip As Outlook.recipient
  4. Dim pa As Outlook.PropertyAccessor
  5. Dim prompt, strMsg, myText As String
  6. Dim NewMail As MailItem, oInspector As Inspector
  7.  
  8. myText = "HERE IS THE TEXT TO BE ADDED"
  9.  
  10.  
  11. Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
  12.  
  13. Set recips = Item.Recipients
  14. For Each recip In recips
  15. Set pa = recip.PropertyAccessor
  16. If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@nhs.net") = 0 Then
  17. strMsg = strMsg & " " & pa.GetProperty(PR_SMTP_ADDRESS) & vbNewLine
  18. End If
  19. Next
  20.  
  21.  
  22. Set oInspector = Application.ActiveInspector
  23. If oInspector Is Nothing Then
  24. MsgBox "No active inspector"
  25. Else
  26. Set NewMail = oInspector.CurrentItem
  27. If NewMail.Sent Then
  28. MsgBox "This is not an editable email"
  29. Else
  30. If oInspector.IsWordMail Then
  31.  
  32. Dim oDoc As Object, oWrdApp As Object, oSelection As Object
  33. Set oDoc = oInspector.WordEditor
  34. Set oWrdApp = oDoc.Application
  35.  
  36. If strMsg = "" Then 'All the recipients are internal to the organisation.
  37.  
  38. 'Add contact line to bottom of signature
  39. oWrdApp.ActiveDocument.Content.InsertAfter myText
  40. With oWrdApp.ActiveDocument.Content.Paragraphs.Last
  41. .Range.Font.Bold = True
  42. .Alignment = wdAlignParagraphCenter
  43. End With
  44. End If
  45.  
  46. Set oWrdApp = Nothing
  47. Set oDoc = Nothing
  48.  
  49. End If
  50. End If
  51. End If
  52. End Sub
  53.  
  54. Dear Somebody,
  55. Here is the body of my email!
  56. Kind Regards,
  57. TM
  58.  
  59. Here is my sig
  60. ** and here is the line added by the VBA **
  61.  
  62. Hi Somebody,
  63. Thanks for your reply. Here's what I think ......
  64.  
  65. Good to hear from you,
  66. TM
  67.  
  68. Here is my sig
  69.  
  70. _______________________________________________
  71. From: Somebody
  72. Sent: Sometime
  73.  
  74. Hi TM,
  75. Here's the reply to your original email!
  76. Thanks,
  77. Somebody
  78.  
  79. ________________________________________________
  80. From: TM
  81. Sent: Initial email
  82. Dear Somebody,
  83. Here is the body of my email!
  84. Kind Regards,
  85. TM
  86.  
  87. Here is my sig
  88. ** and here is the line added by the VBA **initially** **
  89. **** This is the line added by the VBA when I reply or fwd ****
  90. **** It needs to be beneath the signature in the email currently being drafted!!
Add Comment
Please, Sign In to add comment