VBA help to send pdf attachments via Outlook to Excel distribution list

dbwiz

Active Member
Joined
Nov 20, 2007
Messages
275
I need help with VBA code to add to my Excel Distribution list that when run, would look for the path, grab the file that starts with the client name in Col A, and attach to the email, along with a predefined message/header.

The distribution list has the following:

Excel Workbook
ABCDE
1Client NameEmailFirst NameLast NamePath
2ABCJaneDoe@abc.comJaneDoeQ:\Agency Bill\PDF Invoices\2012 Installments\Jan 12
Sheet1
Excel 2007



I would want the email heading to be Installment Invoice and to say something like Dear First Name,
editable text (for example, "Attached please find a copy of your invoice dated"
last portion of path name ( in this case, Jan 12).

More editable text.
Insert Outlook signature.

I have been looking around and have found ways to generate and email pdfs from Excel - however our invoicing system generates bulk pdfs which we have to break up and save to file, in a path like the one above, and then manually select them one by one, typing in the email address, etc. We are hoping to automate the last step of this. Any help/tips would be greatly appreciated!
 
I have a similar situation. I have an email (in Outlook) that I need to send to a list of recipients located in an excel file. I have the email in a word document, but want to add an attachment. How can I send the email with an attachment? I have done coding in the past, but it has been a long time. I would appreciate your help.
Thanks,
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I've got a similar question here: I created a macro that created PDFs into a folder and am trying to create a macro that automates the sending theses PDFs as attachments in outlook. My reference table is currently set up as follows:

Name Email File
Name1 Email1 File_Loc1
Name2 Email2 File_Loc2
Name3 Email3 File_Loc3

My code is as follows:

Sub Mail_FSPDF()


Dim OutApp As Object
Dim OutMail As Object
Dim FS As String
Dim Path As String
Dim Dte As String
Dim FSFile As String
Dim AttachFile As String
Dim MailBody As String
'Dim Rng As String




Set outlookOBJ = CreateObject("Outlook.Application")

Set Rng = ThisWorkbook.Sheets("Emails").Range("a2:A215")
For Each cell In Rng

Path = cell.Value
If Path <> "" Then

FS = cell.Offset(0, 2).Value
Dte = Right(File, Len(File) - InStrRev(File, "\"))

FSFile = Dir(File & "\*.*")

Do While FSFile <> ""

If InStr(FSFile, FS) > 0 Then

AttachFile = Path & "\" & FSFile

MailBody = "See the February 2015 Field Scorecard Attached"

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(o)
With OutMail
.Subject = "February 2015 Field Scorecard"
.To = SendName
.Body = MailBody
.Attachments.Add (AttachFile)
.Display
'.Send
End With

Set OutMail = Nothing
Set OutApp = Nothing
End If
FSFile = Dir
Loop
End If
Next
End Sub
 
Last edited:
Upvote 0
Hello,
I know this is an old post; but this is exactly what i was looking for. I was hoping i can get some assistance, Everything in the code work perfectly beside the CC portion where it duplicate the recipients email in the CC in some cases, i would like to be able to have recipient 2, 3 , 4 and 5 in CC case. can any of you help with this please .
WHOTOFirst NameD-LastD-EmailRecipient 2Recipient 3Recipient 4Recipient 5Path
BERLNKarim1123TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
LEIPZAkram2124TEST@CompanyAB.comTEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
CINCIIsmail3125TEST@CompanyAB.comTEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
INDMeryem4126TEST@CompanyAB.comTEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
ODESAKamal5127TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
TULSAFarid6128TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
KONEHafid7129TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
OKCDriss8130TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
ALBNYAbdeljalil9131TEST@CompanyAB.comTEST@CompanyAB.comTEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
ESSEXHassania10132TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
SWLOUHicham11133TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
WSTCHsamad12134TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
BADGRFaysal13135TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
DBORNKhalid14136TEST@CompanyAB.comTEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
NORWKIsam15137TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
ARBORYoussef16138TEST@CompanyAB.comTEST@CompanyAB.comTEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
MEMPHSamir17139TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
FRANKHassan18140TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
MAFSTZakaria19141TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
STAVALamia20142TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
AMSTRJanat21143TEST@CompanyAB.comTEST@CompanyAB.comTEST@CompanyAB.comTEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
BANGAImane22144TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
CHNAIInass23145TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
SWDLIHouda24146TEST@CompanyAB.comTEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
XHITEZineb25147TEST@CompanyAB.comTEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
XINDUChamae26148TEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013
XOGBANawal27149TEST@CompanyAB.comTEST@CompanyAB.comC:\Users\kmahraz\Desktop\May 2013

<tbody>
</tbody>
 
Upvote 0
Hi Dave,

This code works perfect. However, on my data, there are values in column B that have the same value in column A. How can I make the code to look for the pdf files in the path that matches values in column B and attach them to the same email if they have the same value in Column A?
 
Upvote 0
You'd need to post the actual code you are using, an example of your sheet with at least one matching and one non-matching row and what you expect it to mail.
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,301
Members
449,095
Latest member
Chestertim

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