Excel Macro which Grabs Attachment from Folder Path

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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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