Guest User

Untitled

a guest
Jan 19th, 2018
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. NewMsg.BodyFormat = olFormatHTML
  2. NewMsg.save
  3.  
  4. NewMsg.BodyFormat = olFormatRichText
  5. NewMsg.save
  6. NewMsg.BodyFormat = olFormatHTML
  7. NewMsg.save
  8.  
  9. Private WithEvents Items As Outlook.Items
  10. Private Sub Application_Startup()
  11. Dim olApp As Outlook.Application
  12. Dim objNS As Outlook.NameSpace
  13. Set olApp = Outlook.Application
  14. Set objNS = olApp.GetNamespace("MAPI")
  15. ' default local Inbox
  16. Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
  17. End Sub
  18.  
  19. Private Sub Items_ItemAdd(ByVal item As Object)
  20. On Error GoTo ErrorHandler
  21. Dim Msg As Outlook.MailItem
  22. Dim NewMsg As Outlook.MailItem
  23.  
  24. If TypeName(item) = "MailItem" Then
  25.  
  26. Set Msg = item
  27.  
  28. If Msg.SenderEmailAddress <> "example@example.com" Then GoTo Skip
  29.  
  30. If InStr(1, Msg.Subject, "Specific String") > 0 Then
  31.  
  32. Set NewMsg = Application.CreateItemFromTemplate("Template Path")
  33.  
  34. Msg.Subject = Replace(Msg.Subject, "Give message new subject", "New subject")
  35. Msg.Save
  36.  
  37. 'NewMsg.BodyFormat = olFormatRichText
  38. 'NewMsg.save
  39. 'NewMsg.BodyFormat = olFormatHTML
  40. 'NewMsg.save
  41.  
  42. NewMsg.Attachments.Add Msg
  43.  
  44. NewMsg.Recipients.Add("Example@Example.com")
  45. NewMsg.Subject = Msg.Subject
  46.  
  47. 'NewMsg.Display
  48. NewMsg.Send
  49.  
  50. End If
  51.  
  52. End If
  53.  
  54. Skip:
  55. ProgramExit:
  56.  
  57. Exit Sub
  58. ErrorHandler:
  59. MsgBox Err.Number & " - " & Err.Description
  60.  
  61. End Sub
Add Comment
Please, Sign In to add comment