Hi, I have a very simple macro to print multiple worksheets to separate pdfs. It works fine but I need to clean up the results. I was hoping to get some help from the experts on this forum. I am printing customer invoices with each worksheet.
Here is the current code.
Sub SaveWorksheetsAsPDFs()
Dim sFile As String
Dim sPath As String
Dim wks As Worksheet
With ActiveWorkbook
sPath = .Path & "\"
For Each wks In .Worksheets
sFile = "09 2014 " & wks.Name & ".pdf"
wks.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=sPath & sFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Next wks
End With
End Sub
I would like to improve this with the following features.
1. For the code noted in red (sFile): I would like to set the file name automatically to select the prior month in this format. {MM YYYY "worksheet name"}
2. For the code noted in blue (sPath): I would like to start in the current directory but create a folder called "Invoice Copies". Therefore the pathname would be the "current directory"\Invoice Copies\"new pdfs".
3. For the code noted in green (.worksheets): I would like to select only the invoice worksheets. There are about 4 worksheets that are data only and do not need to print.
Any help on any of the three items above is greatly appreciated.
Thank you
Here is the current code.
Sub SaveWorksheetsAsPDFs()
Dim sFile As String
Dim sPath As String
Dim wks As Worksheet
With ActiveWorkbook
sPath = .Path & "\"
For Each wks In .Worksheets
sFile = "09 2014 " & wks.Name & ".pdf"
wks.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=sPath & sFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Next wks
End With
End Sub
I would like to improve this with the following features.
1. For the code noted in red (sFile): I would like to set the file name automatically to select the prior month in this format. {MM YYYY "worksheet name"}
2. For the code noted in blue (sPath): I would like to start in the current directory but create a folder called "Invoice Copies". Therefore the pathname would be the "current directory"\Invoice Copies\"new pdfs".
3. For the code noted in green (.worksheets): I would like to select only the invoice worksheets. There are about 4 worksheets that are data only and do not need to print.
Any help on any of the three items above is greatly appreciated.
Thank you