How to send automated email in Outlook with pdf attached

Greyluke

New Member
Joined
Jun 17, 2016
Messages
1
Hi,

sorry if this has already been posted, but I was not able to find anything similar. I have an Access query which contains a list of recipients. It looks like this:

CODE EMAIL
000001 xxxxxxxxx@mail.com
000002 yyyyyyyyy@mail.com
...

Then I have all pdf files i need to send in a folder. The pdf files are named after the code I need to send them to.

So for example, I need to send an email to xxxxxxxxx@mail.com (which is code 000001) with attached file named 000001.pdf, an email to yyyyyyyyy@mail.com (code 000002) with attached file 000002.pdf, and so on.

How can I accomplish that with VBA?

Many thanks in advance
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You can use the DoCmd.SendObject method or use Automation. For that, a search on "ms access send attachment email" produced 3.7 million results, so when you say you have not found what you need, you must be referring to something else. If that is how to match the file name with the email recipient, you'll have to find code that will work for you insofar as sending an attachment is concerned. Then you'll need to adapt it to find the file.

For that, I would first, find the position of the @ character using Instr and Left functions, then extracting from the address all that precedes that character, then find the file that matches that string once you've appended the extension ".pdf" to the first part. In one step, something like this
Code:
strFileName = Left(emailAddress,Instr(emailAddress,"@"))-1 & ".pdf"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,813
Messages
6,162,126
Members
451,743
Latest member
matt3388

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