Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Public Sub SendScorecards()
- Dim olApp As Object
- Dim olMail As Object
- Dim olRecip As Object
- Dim olAtmt As Object
- Dim olAtmt2 As Object
- Dim iRow As Long
- Dim Recip As String
- Dim Subject As String
- Dim Atmt As String
- Dim Atmt2 As String
- iRow = 2
- Set olApp = CreateObject("Outlook.Application")
- Dim Sht As Worksheet
- Set Sht = ThisWorkbook.Worksheets("Sender")
- Do Until IsEmpty(Sht.Cells(iRow, 1))
- Recip = Sht.Cells(iRow, 1).Value 'Email addresses
- Subject = Sht.Cells(iRow, 2).Value 'Subject of the email, like "UK_Vendor name_Operations Scorecard"
- Atmt = Sht.Cells(iRow, 3).Value 'PDF attachment path
- Atmt2 = Sht.Cells(iRow, 4).Value 'Excel attachment path
- Set olMail = olApp.CreateItem(0)
- With olMail
- Set olRecip = .Recipients.Add(Recip)
- .Subject = Subject
- .Body = Sht.Cells.Range("J2") 'Blurb to be added in the body of the emails
- .Display
- Set olAtmt = .Attachments.Add(Atmt)
- If Atmt = 0 Then
- Set olAtmt2 = .Attachments.Add(Atmt2)
- olRecip.Resolve
- .Send
- End With
- On Error Resume Next
- iRow = iRow + 1
- Loop
- Set olApp = Nothing
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement