error on sending email - 2 lines of code i need help on

eric86vabeach

New Member
Joined
Jan 29, 2014
Messages
23
i need help on 2 lines of code


Sub sendemail(subject_line As String, mail_body As String)



Dim olapp As Outlook.Application
Set olapp = CreateObject("outlook.application")


Dim olMail As Outlook.MailItem
setolmail = olapp.CreateItem(olMailItem)

olMail.To = Sheet4.Range("BA") '-this line i need help
olMail.Sub = subject_line
olMail.Body = mail_body
olMail.Send


End Sub



Sub sendmassemail()

row_number = Range("BQ1").Value
Do
DoEvents
row_numbers = row_number + 1
Call sendemail(Sheet4.Range("BD" & row_number), Sheet5.Range("BV2")) '-this line i need help
Loop Until row_number >= 6

End Sub




thanks for reading and thanks
eric
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
What help do you need....is there an error or a incorrect result ??
But as a guess
this line
Code:
olMail.To = Sheet4.Range("BA")
Needs a row reference..like "BA1"
 
Upvote 0
There were quite a few errors with your code, but sticking as close to your original code as possible, you could try

Code:
Sub sendemail(subject_line As String, mail_body As String)

Dim olapp As Outlook.Application
Set olapp = CreateObject("outlook.application")


Dim olMail As Outlook.MailItem
Set olMail = olapp.CreateItem(olMailItem)


olMail.To = Sheet4.Range("BA1") '-this line i need help
olMail.Subject = subject_line
olMail.Body = mail_body
olMail.Send


End Sub


Sub sendmassemail()


row_number = Range("BQ1").Value
Do
DoEvents
row_number = row_number + 1
Call sendemail(Sheet4.Range("BD" & row_number), Sheet5.Range("BV2")) '-this line i need help
Loop Until row_number >= 6


End Sub

Hope this helps

Simon
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,262
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top