Hi,
I have a macro that will toggle through a pivot table, save each report as a pdf into a folder, and print the report. Is it possible to have it send each pdf to outlook with a specific message in the text?
Thanks!PHP Code:
Option Explicit
Sub MakePDF()
If Dir(ThisWorkbook.Path & "\" & MonthName(Month(Date)), vbDirectory) = MonthName(Month(Date)) Then
MsgBox "Folder already exists!"
Else
MkDir Application.ThisWorkbook.Path & "\" & MonthName(Month(Date))
End If
Dim shC As Worksheet ' Collection Officer worksheet
Dim pt As PivotTable ' Pivot Table
Dim pf As PivotField ' Pivot field
Dim pi As PivotItem ' Pivot item
Dim LrowC As Long ' Last row on worksheet.
Dim cl As Range ' Pointer to list of collection officers
Dim PathName As String ' Path to PDF File (current folder)
Dim FileName As String ' PDF FileName
' initalize variables
Set shC = Sheets("Collection Officer")
Set pt = shC.PivotTables(1)
Set pf = pt.PivotFields("Collection Officer")
PathName = ThisWorkbook.Path & "\" & MonthName(Month(Date))
For Each cl In Range("Collection_Officers")
' Get last row
LrowC = shC.Range("A" & Rows.Count).End(xlUp).Row
' Make file name and set the print area
FileName = cl.Value & ".pdf"
shC.PageSetup.PrintArea = "$A$1:$E$" & LrowC
' Filter the pivot table
pf.ClearAllFilters ' Clear the old filter to show all
For Each pi In pf.PivotItems ' Turn off items we don't want to see
If pi.Value <> cl.Value Then
pi.Visible = False
End If
Next pi
' Print - added by callum
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
ActiveWindow.SmallScroll Down:=-60
Range("A1").Select
' Publish as PDF
shC.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
PathName & "\" & FileName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Next cl
' clear pivot table
pf.ClearAllFilters
End Sub
Bookmarks