last day (15 days later) » 

12:32 PM
0
A: Sending multiple email using range with attachment in VBA

z32a7ulYou need a loop for that. The below code will start with the second row and continue until it finds an empty row. Option Explicit Sub SendMail() Dim objOutlook As Object Dim objMail As Object Dim rngTo As Range Dim rngSubject As Range Dim rngBody As Range Dim rngAttach A...

 
regarding r = 2 is number of row right
 
Sorry, I don't understand your comment.
 
I have query here Dim r As Long: For r = 2 To ActiveSheet.Range("C2").End(xlDown).Row what is R = 2
 
That is not a query, it is a loop. r will be equal to 2, then 3, then ... until an empty row is encountered. And for each value of r, an email will be sent. The code references r for example in this line: Set rngTo = .Range("C" & r), so at the first iteration it reads from C2, then from C3, etc.
 
actually I am getting different error if I am altering the r = 5 Automation error unspecified error In your code if i am entering 5 it was selecting 5 row but i want 1 - 5 rows Can you please help me here
 
12:35 PM
Hi
What do you mean by that? Did you modify the code to For r = 5 To ...? Or did you stop it at the 5th iteration? Do you have any data in row 5?
 
hi yes
I have the data for 1 - 10
 
So, did you modify the code, or did you stop it at the 5th iteration?
 
i have not modify the code actually I am new to vba just learning with your code it was attaching all files in one single email instead of multiple with attachement
 
What do the cells C5, E5, G5, and F5 contain?
 
if you see me question i was mention that C2 - to email D2 - cc email e2 - subj
like that
body
 
12:47 PM
I saw that
 
if you see mikku code it was near but there is a error
 
I ask, what does your Excel sheet contain in those cells? Are those valid data?
 
yes
valid data
 
On which line does the error come up?
 
For i = 2 To 21 ' Loop from 2 to 21
he didn't declare the var it seems
for i
 
12:50 PM
On which line does the error come up in my code?
 
i got it with mithun code
it was working
I declared variable
 
Well, I think I see the problem. Set objMail = objOutlook.CreateItem(0) has to be inside the loop.
I updated my answer.
 
1:21 PM
What do you mean by that Range is not working?
 

last day (15 days later) »