Sending emails to multiple recipients with multiple PDF files via VBA & Excel

The25th

New Member
Joined
Jun 19, 2019
Messages
6
I'm very new to VBA and found a code online that sends emails to multiple recipients but can only attach 1 file per email. I cannot find a code that works wherein it goes to a specific folder and attaches all PDF files that are stored in the folder and goes to a different folder and does the same for the next email recipient. The image shows the structure of the sheet that I am working on. I'm using Office 365.

Need help please, thank you.

Here's the Excel structure:
9RB1o.png


Here's my code:

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub SendMail()

ActiveWorkbook
.RefreshAll

Dim objOutlook AsObject
Dim objMail AsObject
Dim ws As Worksheet

Set objOutlook = CreateObject("Outlook.Application")
Set ws = ActiveSheet

OnErrorGoTo MyHandler

ForEach cell In ws.Range("A2:A2000")

Set objMail = objOutlook.CreateItem(0)

With objMail
.To= cell.Value
.Cc ="email@email.com"
.Subject = cell.Offset(0,1).Value
.Body = cell.Offset(0,2).Value
.Attachments.Add cell.Offset(0,3).Value
.Display
EndWith

Set objMail =Nothing
Next cell

Set ws =Nothing
Set objOutlook =Nothing

MyHandler
:
MsgBox
"Review email messages"

EndSub</code>
 
Hi, I found this code very helpful with what I need, however, this code attaches all the files in the folder path.
Can it be modified to attach the files that will only match the file name in column F?

Thanks in advance.
 
Upvote 0

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,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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