ExcelAtEverything
Active Member
- Joined
- Jan 30, 2021
- Messages
- 351
- Office Version
- 2019
- Platform
- Windows
I have code already that selects 10 of the 20 or so worksheets in my workbook. The next part of the code (shown below) is what I need help with.
As it stands, this code below will print every worksheet in my workbook as a PDF, and name each PDF as the same name as the sheet it was printed from (the name of the tab/worksheet).
But I need to change it so that it only prints a PDF copy of each sheet that's currently selected, and names each PDF as (Worksheet name) & the date. The date needs to be the date that exists already in the workbook in cell $G$3 of "Sheet1", if that's possible.
Dim ws As Worksheet
Dim folderPath As String
folderPath = "C:\Users\myname\Downloads\"
If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
For Each ws In ThisWorkbook.Worksheets
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=folderPath & ws.Name & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Next
'
End Sub
Thanks!
As it stands, this code below will print every worksheet in my workbook as a PDF, and name each PDF as the same name as the sheet it was printed from (the name of the tab/worksheet).
But I need to change it so that it only prints a PDF copy of each sheet that's currently selected, and names each PDF as (Worksheet name) & the date. The date needs to be the date that exists already in the workbook in cell $G$3 of "Sheet1", if that's possible.
Dim ws As Worksheet
Dim folderPath As String
folderPath = "C:\Users\myname\Downloads\"
If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
For Each ws In ThisWorkbook.Worksheets
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=folderPath & ws.Name & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Next
'
End Sub
Thanks!