Hello ! I am trying do deploy a similar vba code. The end goal is to load an excel file and extract some data in it including some emails. After that another macro is triggered which sends mails. Unfortunately, when there are no email addresses populated into the file, I get the same error message. Could please help me solve this issue and modify my macro. I use the following code:
Sub Sendemail(what_address As String, subject_line As String, mail_body As String)
Dim olapp As Outlook.Application
Dim olemail As Outlook.MailItem
Set olapp = New Outlook.Application
Set olemail = olapp.CreateItem(olMailItem)
Dim last_row As Integer
With olemail
.BodyFormat = olFormatHTML
.HTMLBody = mail_body
.To = what_address
.Subject = subject_line
.BodyFormat = olFormatPlain
.Send
End With
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 Body_Difference As String
mail_body_message = Sheet1.Range("N1")
full_name = Sheet1.Range("D" & row_number)
Body_Difference = Sheet1.Range("J" & row_number)
mail_body_message = Replace(mail_body_message, "replace_name_here", full_name)
mail_body_message = Replace(mail_body_message, "Body_Difference_replace", Body_Difference)
Call Sendemail(Sheet1.Range("E" & row_number), "This is a test email", mail_body_message)
Loop Until row_number = Sheet1.Range("E99999").End(xlUp).Row
Loop
End Sub
Bookmarks