VBA code to take PDF file in folder & attach to outlook email

bumbum2812

New Member
Joined
Sep 7, 2020
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi Experts

Please help me to modify below code to take all PDF file contain specific word like "ReportA", "ReportB"
j 2 to 3 is my third column with exact file name & file extension.


VBA Code:
Sub send_email_complete()
Dim outlookApp As Object
Dim myMail As Object
Dim source_file, to_emails, cc_emails As String
Dim i, j As Integer
Dim An As String
Dim folderPath As String
folderPath = Application.ActiveWorkbook.Path


    An = Application.UserName
    Set outlookApp = CreateObject("Outlook.Application")
    Set myMail = outlookApp.CreateItem(0)
With myMail
For i = 2 To 2
    to_emails = to_emails & Cells(i, 1) & ";"
    cc_emails = cc_emails & Cells(i, 2) & ";"
Next i

For j = 2 To 3
    source_file = folderPath & "\" & Cells(j, 3)
    .Attachments.Add source_file
Next

ThisWorkbook.Save
source_file = ThisWorkbook.FullName
.Attachments.Add source_file

.CC = cc_emails
.To = to_emails
.Subject = "Files for Everyone"
.Body = "Hi Everyone," & vbNewLine & "Please read these before the meeting." & vbNewLine & "Thanks"

.Display
End With

End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,215,770
Messages
6,126,791
Members
449,336
Latest member
p17tootie

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