Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
201
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. File1.xls recipient1@email.com
  3. File2.xls recipient2@email.com
  4. File3.xls recipient3@email.com
  5. File4.xls recipient4@email.com
  6.  
  7. End with without with
  8.  
  9. End With
  10.  
  11. Sub email()
  12.  
  13. 'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
  14. 'Working in Office 2000-2016
  15.  
  16. 'Variables
  17. Dim cell As Range
  18.  
  19. Application.ScreenUpdating = False
  20.  
  21. Dim Maildb As Object
  22. Dim MailDoc As Object
  23. Dim Body As Object
  24. Dim Session As Object
  25.  
  26. 'Start a session of Lotus Notes
  27. Set Session = CreateObject("Lotus.NotesSession")
  28.  
  29. 'This line prompts for password of current ID noted in Notes.INI
  30. Call Session.Initialize
  31.  
  32. 'or use below to provide password of the current ID (to avoid Password prompt)
  33. 'Call Session.Initialize("<password>")
  34. 'Open the Mail Database of your Lotus Notes
  35. Set Maildb = Session.GETDATABASE("", "D:NotesdataMaileXceLiTems.nsf")
  36. If Not Maildb.IsOpen = True Then
  37. Call Maildb.Open
  38. End If
  39.  
  40. 'Loop
  41.  
  42. On Error GoTo cleanup
  43. For Each cell In Columns("V").Cells.SpecialCells(xlCellTypeConstants)
  44. If cell.Value Like "?*@?*.?*" And _
  45. LCase(Cells(cell.Row, "G").Value) <> "" Then
  46.  
  47. 'Email COde
  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. 'Email Body
  58. Call Body.APPENDTEXT("Good " & Range("A1").Value & "," _
  59. & vbNewLine & vbNewLine & _
  60. "Thank you for your interest in participating in this weeks special promotion. Please see the details below." _
  61. & vbNewLine & vbNewLine _
  62. & vbNewLine & vbNewLine _
  63. & Range("I10").Value _
  64. & vbNewLine & vbNewLine _
  65. & "Thank you and kind regards / Danke und freundliche Gr??e," _
  66. & vbNewLine & vbNewLine _
  67. & "The Food Specials Team" _
  68. & vbNewLine)
  69. 'End Email Body
  70.  
  71. 'Example to create an attachment (optional)
  72. Call Body.ADDNEWLINE(2)
  73. Call Body.EMBEDOBJECT(1454, "", Filename, cell.Offset(0, -19).Value)
  74.  
  75. 'Example to save the message (optional) in Sent items
  76. MailDoc.SAVEMESSAGEONSEND = True
  77.  
  78. 'Send the document
  79. 'Gets the mail to appear in the Sent items folder
  80. Call MailDoc.REPLACEITEMVALUE("PostedDate", Now())
  81. Call MailDoc.SEND(True)
  82.  
  83. 'Clean Up the Object variables - Recover memory
  84. 'End Loop
  85.  
  86. End With ' <---- Remove this End With
  87. On Error GoTo 0
  88. Set OutMail = Nothing
  89. End If
  90.  
  91. Next cell
  92.  
  93. cleanup:
  94. Set Maildb = Nothing
  95. Set MailDoc = Nothing
  96. Set Body = Nothing
  97. Set Session = Nothing
  98.  
  99. Application.ScreenUpdating = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement