Option Explicit
Public Sub Email_PDF_To_All_People()
Dim DVcell As Range
Dim DVsource As Range
Dim DVvalue As Range
Dim PDFsFolder As String, PDFfile As String
PDFsFolder = ActiveWorkbook.Path & "\"
If Right(PDFsFolder, 1) <> "\" Then PDFsFolder = PDFsFolder & "\"
Application.ScreenUpdating = False
With ActiveSheet
Set DVcell = .Range("B6")
Set DVsource = Evaluate(DVcell.Validation.Formula1)
For Each DVvalue In DVsource
DVcell.Value = DVvalue
PDFfile = PDFsFolder & DVcell.Value & ".pdf"
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfile, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Send_Outlook_Email .Range("O6").Value, "Report for " & DVvalue, PDFfile
Next
End With
Application.ScreenUpdating = True
MsgBox "Done"
End Sub
Public Sub Send_Outlook_Email(toEmail As String, emailSubject As String, attachPDFfile As String)
Static OutApp As Object
Dim OutEmail As Object
Const olMail = 0
If OutApp Is Nothing Then
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
If Err Then
Set OutApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0
End If
Set OutEmail = OutApp.CreateItem(olMail)
With OutEmail
.To = toEmail
.Subject = emailSubject
.Body = "Body text here"
.Attachments.Add attachPDFfile
.Display 'or .Send
End With
End Sub