freshprince
New Member
- Joined
- Dec 28, 2016
- Messages
- 1
Hey Guys
I have written a macro that will automatically fill in blanks from a email template i have created within Excel. However, i would also like to create some code that will attach a file from a folder and add it to the email.
Within the excel workbook i have specified the file location. The path is in Column Z. Trying to find a way to attach the file from the file path specified in column Z into the email before i send it out.
Here is the code i have already written
Sub SendEmail(what_address As String, who_cc 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.CC = who_cc
olMail.Subject = subject_line
olMail.Body = mail_body
olMail.Display
End Sub
Sub SendMassEmail()
row_number = 1
Do
DoEvents
row_number = row_number + 1
Dim what_address As String
Dim subject_line As String
Dim who_cc As String
Dim mail_body_message As String
Dim Delivery_date As String
Dim likelihood As String
Dim timeframe As String
what_address = Sheet1.Range("T" & row_number)
subject_line = Sheet1.Range("R" & row_number)
who_cc = Sheet1.Range("W" & row_number)
mail_body_message = Sheet1.Range("N" & row_number)
Delivery_date = Sheet1.Range("F" & row_number)
timeframe = Sheet1.Range("U" & row_number)
likelihood = Sheet1.Range("V" & row_number)
mail_body_message = Replace(mail_body_message, "<Delivery_Date>", Delivery_date)
mail_body_message = Replace(mail_body_message, "<likelihood>", likelihood)
mail_body_message = Replace(mail_body_message, "<timeframe>", timeframe)
'olMail.Attachments.Add = "Z:" & Attachment
'MsgBox mail_body_message
Call SendEmail(what_address, who_cc, subject_line, mail_body_message)
Loop Until row_number = 2
End Sub
I have written a macro that will automatically fill in blanks from a email template i have created within Excel. However, i would also like to create some code that will attach a file from a folder and add it to the email.
Within the excel workbook i have specified the file location. The path is in Column Z. Trying to find a way to attach the file from the file path specified in column Z into the email before i send it out.
Here is the code i have already written
Sub SendEmail(what_address As String, who_cc 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.CC = who_cc
olMail.Subject = subject_line
olMail.Body = mail_body
olMail.Display
End Sub
Sub SendMassEmail()
row_number = 1
Do
DoEvents
row_number = row_number + 1
Dim what_address As String
Dim subject_line As String
Dim who_cc As String
Dim mail_body_message As String
Dim Delivery_date As String
Dim likelihood As String
Dim timeframe As String
what_address = Sheet1.Range("T" & row_number)
subject_line = Sheet1.Range("R" & row_number)
who_cc = Sheet1.Range("W" & row_number)
mail_body_message = Sheet1.Range("N" & row_number)
Delivery_date = Sheet1.Range("F" & row_number)
timeframe = Sheet1.Range("U" & row_number)
likelihood = Sheet1.Range("V" & row_number)
mail_body_message = Replace(mail_body_message, "<Delivery_Date>", Delivery_date)
mail_body_message = Replace(mail_body_message, "<likelihood>", likelihood)
mail_body_message = Replace(mail_body_message, "<timeframe>", timeframe)
'olMail.Attachments.Add = "Z:" & Attachment
'MsgBox mail_body_message
Call SendEmail(what_address, who_cc, subject_line, mail_body_message)
Loop Until row_number = 2
End Sub