Hi all,
I have tried to learn just enough VBA to get a simple task done, and I'm stuck. Your guidance would be appreciated.
This basic code I copied and manipulated from Youtube...
I am setting this up in attempts to populate emails, each with a unique recipient, subject line, message, and attachment.
I have everything figured out except the attachment. Each unique attachment file path is in column F on sheet 1.
Also, in a perfect world, I would like the macro to loop the number of rows are in the workbook automatically, instead of the loop stopping at 6.
Code:
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.Display
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
Call SendEmail(Sheet1.Range("d" & row_number), Sheet1.Range("a" & row_number), Sheet1.Range("e" & row_number))
Loop Until row_number = 6
End Sub
I have tried to learn just enough VBA to get a simple task done, and I'm stuck. Your guidance would be appreciated.
This basic code I copied and manipulated from Youtube...
I am setting this up in attempts to populate emails, each with a unique recipient, subject line, message, and attachment.
I have everything figured out except the attachment. Each unique attachment file path is in column F on sheet 1.
Also, in a perfect world, I would like the macro to loop the number of rows are in the workbook automatically, instead of the loop stopping at 6.
Code:
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.Display
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
Call SendEmail(Sheet1.Range("d" & row_number), Sheet1.Range("a" & row_number), Sheet1.Range("e" & row_number))
Loop Until row_number = 6
End Sub