Guest User

Untitled

a guest
Jan 18th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. Column G Column W
  2.  
  3. End with without with
  4.  
  5. End With
  6.  
  7. Sub email()
  8.  
  9. 'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
  10. 'Working in Office 2000-2016
  11.  
  12. 'Variables
  13. Dim cell As Range
  14.  
  15.  
  16.  
  17. Application.ScreenUpdating = False
  18.  
  19. Dim Maildb As Object
  20. Dim MailDoc As Object
  21. Dim Body As Object
  22. Dim Session As Object
  23. 'Start a session of Lotus Notes
  24. Set Session = CreateObject("Lotus.NotesSession")
  25. 'This line prompts for password of current ID noted in Notes.INI
  26. Call Session.Initialize
  27. 'or use below to provide password of the current ID (to avoid Password prompt)
  28. 'Call Session.Initialize("<password>")
  29. 'Open the Mail Database of your Lotus Notes
  30. Set Maildb = Session.GETDATABASE("", "D:NotesdataMaileXceLiTems.nsf")
  31. If Not Maildb.IsOpen = True Then
  32. Call Maildb.Open
  33. End If
  34.  
  35.  
  36.  
  37. 'Loop
  38.  
  39. On Error GoTo cleanup
  40. For Each cell In Columns("V").Cells.SpecialCells(xlCellTypeConstants)
  41. If cell.Value Like "?*@?*.?*" And _
  42. LCase(Cells(cell.Row, "G").Value) <> "" Then
  43.  
  44.  
  45. 'Email COde
  46.  
  47.  
  48. Set MailDoc = Maildb.CREATEDOCUMENT
  49. Call MailDoc.REPLACEITEMVALUE("Form", "Memo")
  50. 'Set the Recipient of the mail
  51. Call MailDoc.REPLACEITEMVALUE("SendTo", cell.Value)
  52. 'Set subject of the mail
  53. Call MailDoc.REPLACEITEMVALUE("Subject", "Attention Required: Promotion Announcement for Week " & Range("O10").Value & " " & Range("O13").Value)
  54. 'Create and set the Body content of the mail
  55. Set Body = MailDoc.CREATERICHTEXTITEM("Body")
  56.  
  57.  
  58. 'Email Body
  59.  
  60. Call Body.APPENDTEXT("Good " & Range("A1").Value & "," _
  61. & vbNewLine & vbNewLine & _
  62. "Thank you for your interest in participating in this weeks special promotion. Please see the details below." _
  63. & vbNewLine & vbNewLine _
  64. & vbNewLine & vbNewLine _
  65. & Range("I10").Value _
  66. & vbNewLine & vbNewLine _
  67. & "Thank you and kind regards / Danke und freundliche Grüße," _
  68. & vbNewLine & vbNewLine _
  69. & "The Food Specials Team" _
  70. & vbNewLine)
  71.  
  72.  
  73. 'End Email Body
  74.  
  75.  
  76.  
  77. 'Example to create an attachment (optional)
  78. Call Body.ADDNEWLINE(2)
  79. Call Body.EMBEDOBJECT(1454, "", Filename, cell.Offset(0, -19).Value)
  80. 'Example to save the message (optional) in Sent items
  81. MailDoc.SAVEMESSAGEONSEND = True
  82. 'Send the document
  83. 'Gets the mail to appear in the Sent items folder
  84. Call MailDoc.REPLACEITEMVALUE("PostedDate", Now())
  85. Call MailDoc.SEND(True)
  86. 'Clean Up the Object variables - Recover memory
  87.  
  88.  
  89.  
  90.  
  91. 'End Loop
  92.  
  93. End With
  94. On Error GoTo 0
  95. Set OutMail = Nothing
  96. End If
  97.  
  98. Next cell
  99.  
  100. cleanup:
  101. Set Maildb = Nothing
  102. Set MailDoc = Nothing
  103. Set Body = Nothing
  104. Set Session = Nothing
  105.  
  106. Application.ScreenUpdating = True
  107.  
  108. End Sub
Advertisement
Add Comment
Please, Sign In to add comment