A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi JustinGJR!
Thank you for the feedback and you are highly welcome.
To include the current date in the filename when saving the PDF, you can use the Format function in VBA to format the current date in the desired format.
Please try this: Sub PrintReportsToPDF()
With Sheets("Maint Report"). PageSetup . FitToPagesWide = 1 . FitToPagesTall = False . Orientation = xlLandscape End With
With Sheets("Daily Report"). PageSetup . FitToPagesWide = 1 . FitToPagesTall = 1 . Orientation = xlPortrait End With
Dim sheetsArray() As Variant sheetsArray = Array("Daily Report", "Maint Report")
Sheets(sheetsArray). Select
Sheets("Daily Report"). Activate
Dim fileName As String fileName = "Daily Report " & Format(Date, "m_d_yy") & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _ Filename:="C:\Path\to\your\output" & fileName, _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False, _ OpenAfterPublish:=True
End Sub
In this updated code, the fileName variable is defined as a string that includes the desired prefix "Daily Report" followed by the formatted current date using the Format function. The format string "m_d_yy" specifies the month, day, and year in a two-digit format.
Make sure to adjust the file path in the Filename parameter of the ExportAsFixedFormat method according to your desired output location.
Best Regards, Shakiru