Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. Option Explicit
  2. Public Sub SendScorecards()
  3. Dim olApp As Object
  4. Dim olMail As Object
  5. Dim olRecip As Object
  6. Dim olAtmt As Object
  7. Dim olAtmt2 As Object
  8. Dim iRow As Long
  9. Dim Recip As String
  10. Dim Subject As String
  11. Dim Atmt As String
  12. Dim Atmt2 As String
  13.  
  14. iRow = 2
  15.  
  16. Set olApp = CreateObject("Outlook.Application")
  17. Dim Sht As Worksheet
  18. Set Sht = ThisWorkbook.Worksheets("Sender")
  19.  
  20. Do Until IsEmpty(Sht.Cells(iRow, 1))
  21.  
  22. Recip = Sht.Cells(iRow, 1).Value 'Email addresses
  23. Subject = Sht.Cells(iRow, 2).Value 'Subject of the email, like "UK_Vendor name_Operations Scorecard"
  24. Atmt = Sht.Cells(iRow, 3).Value 'PDF attachment path
  25. Atmt2 = Sht.Cells(iRow, 4).Value 'Excel attachment path
  26.  
  27. Set olMail = olApp.CreateItem(0)
  28.  
  29. With olMail
  30.  
  31. Set olRecip = .Recipients.Add(Recip)
  32. .Subject = Subject
  33. .Body = Sht.Cells.Range("J2") 'Blurb to be added in the body of the emails
  34. .Display
  35. Set olAtmt = .Attachments.Add(Atmt)
  36. If Atmt = 0 Then
  37. Set olAtmt2 = .Attachments.Add(Atmt2)
  38. olRecip.Resolve
  39. .Send
  40.  
  41. End With
  42. On Error Resume Next
  43. iRow = iRow + 1
  44.  
  45. Loop
  46.  
  47. Set olApp = Nothing
  48. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement