Works as expected.
Creates e-mails for the rows if their column K value is YES.
i modified the code to take the greeting/salutation part from column E.
so instead of Dear Sir, mail body starts with Dear Arindom, Dear Nilay, etc.
just make sure columns A, B, C contain valid e-mail addresses and column G valid full file name.
if the name of the file to attach is C:\Users\IqbalM\Desktop\BIN\AR\A.D. REGENCY EXPORTS PVT. LTD.xlsx, a file named A.D. REGENCY EXPORTS PVT. LTD.xlsx must exist in the folder C:\Users\IqbalM\Desktop\BIN\AR\.
and this codes assumes active sheet contains all the mailing info.
so run the code if Sheet1 (taking into account the uploaded file) is the activesheet.
Sub vbax_59255_mass_emailing()
Dim t As Long, LastRow As Long
Dim mBody As String
LastRow = Range("A:C").Find("*", , , , xlByRows, xlPrevious).Row
mBody = vbLf & vbLf
mBody = mBody & "Attached please find Outstanding as on 31.3.2017. Kindly Review and settle overdue Invoices." & vbLf & vbLf
mBody = mBody & "Thanks & Regards" & vbLf
mBody = mBody & "Md Asif Iqbal"
With CreateObject("Outlook.Application")
For t = 3 To LastRow
If UCase(Range("K" & t)) = "YES" Then
With .CreateItem(0)
.VotingOptions = Range("J" & t).Value
.To = Range("A" & t).Value
.CC = Range("B" & t).Value
.BCC = Range("C" & t).Value
.Subject = Range("D" & t).Value
.Body = Range("E" & t).Value & mBody
.Attachments.Add Range("G" & t).Value
.Display
'.Send
End With
End If
Next t
End With
End Sub
test your code with
when testing, make sure there is at least one Yes in K3:K8
Sub vbax_59255_mass_emailing_test()
Dim t As Long, LastRow As Long
Dim mBody As String
LastRow = Range("A:C").Find("*", , , , xlByRows, xlPrevious).Row
mBody = vbLf & vbLf
mBody = mBody & "Attached please find Outstanding as on 31.3.2017. Kindly Review and settle overdue Invoices." & vbLf & vbLf
mBody = mBody & "Thanks & Regards" & vbLf
mBody = mBody & "Md Asif Iqbal"
With CreateObject("Outlook.Application")
For t = 3 To 8 'loop thru 3-8 rows only
If UCase(Range("K" & t)) = "YES" Then
With .CreateItem(0)
.VotingOptions = Range("J" & t).Value
.To = Range("A" & t).Value
.CC = Range("B" & t).Value
.BCC = Range("C" & t).Value
.Subject = Range("D" & t).Value
.Body = Range("E" & t).Value & mBody
.Attachments.Add Range("G" & t).Value
.Display 'just display do not send
End With
End If
Next t
End With
End Sub
PS: i have nothing to add regarding this thread. so i can't reply any further questions like "does not work", "works but not as expected", etc.