MikeSta4ord
06-29-2015, 09:12 AM
Hi, I'm new to VBA coding and I'm having trouble with the last aspect of my code to send mass emails to everyone in an excel database. The Code operates correctly as its sending emails when I specify which row to loop until. Though, When I try to change the loop until statement to loop until it finds an empty cell it keeps returning an error that reads: "Outlook does not recognize one or more names". Not sure why Outlook is recognizing any names since everything is specified through excel.
Here's the code I'm using:
Sub SendEmail(what_address As String, 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 = what_address
olMail.Subject = subject_line
olMail.Body = mail_body
olMail.Send
End Sub
Sub SendMassEmail()
row_number = 1
Do
DoEvents
row_number = row_number + 1
Dim mail_body_message As String
Dim full_name As String
Dim project_name As String
Dim offer_number As String
mail_body_message = Sheet10.Range("G2")
full_name = Sheet10.Range("D" & row_number)
project_name = Sheet10.Range("B" & row_number)
offer_number = Sheet10.Range("C" & row_number)
mail_body_message = Replace(mail_body_message, "Offer_number", offer_number)
mail_body_message = Replace(mail_body_message, "replace_name_here", full_name)
mail_body_message = Replace(mail_body_message, "Project_replace", project_name)
MsgBox mail_body_message
Call SendEmail(Sheet10.Range("A" & row_number), "Following up on our offer", mail_body_message)
Loop Until offer_number = ""
MsgBox "Emails Sent!"
'
End Sub
Any errors you can identify would be greatly appreciated as I have no Idea where to take it from here.
Thank-you
Here's the code I'm using:
Sub SendEmail(what_address As String, 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 = what_address
olMail.Subject = subject_line
olMail.Body = mail_body
olMail.Send
End Sub
Sub SendMassEmail()
row_number = 1
Do
DoEvents
row_number = row_number + 1
Dim mail_body_message As String
Dim full_name As String
Dim project_name As String
Dim offer_number As String
mail_body_message = Sheet10.Range("G2")
full_name = Sheet10.Range("D" & row_number)
project_name = Sheet10.Range("B" & row_number)
offer_number = Sheet10.Range("C" & row_number)
mail_body_message = Replace(mail_body_message, "Offer_number", offer_number)
mail_body_message = Replace(mail_body_message, "replace_name_here", full_name)
mail_body_message = Replace(mail_body_message, "Project_replace", project_name)
MsgBox mail_body_message
Call SendEmail(Sheet10.Range("A" & row_number), "Following up on our offer", mail_body_message)
Loop Until offer_number = ""
MsgBox "Emails Sent!"
'
End Sub
Any errors you can identify would be greatly appreciated as I have no Idea where to take it from here.
Thank-you