I have a workbook template (template.xltm) that has 150 premade worksheets. Obviously from this template I create *.xlsm files. These individual workbooks can grow up to 300 worksheets. I need a macro/VBA that looks at the specific Cell A1 on every worksheet and then prints that worksheet if it is not equal to 0 while also exporting it to a single PDF. The code below is the closest I have found on the web but it prints individual PDFs and not a SINGLE PDF. It meets my criteria except I end up with a ton of PDFs that I then need to merge using Adobe Acrobat. Some A1s will have positive numbers, negative numbers and/or text. But if it is 0 (zero), do not print.
Works but Prints many PDFs instead of a Single PDF.
'-------------------------------------------------------------------------------
Sub Save_as_Pdfs()
'-------------------------------------------------------------------------------
' Saves marked sheets as PDF file.
Const PDF_path = "C:\Reports"
Dim Snr As Integer
Dim Name As String
'Process all sheets in workbook
For Snr = 1 To ActiveWorkbook.Sheets.Count
Sheets(Snr).Activate
'Only print if A1 contains "Y"
If Cells(1, "A").Value <> "0" Then
Name = PDF_path & Snr & ActiveSheet.Name & Cells(1, "A").Value & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
Next Snr
End Sub
*I am also in process of moving to SharePoint (excel web) so obviously VBA doesn't work. My work around is to download any workbooks that I need to run this macro on to my desktop and then run the macro. I'm curious if there is any way to turn this into an office script and output to a specific document folder on SharePoint?
Works but Prints many PDFs instead of a Single PDF.
'-------------------------------------------------------------------------------
Sub Save_as_Pdfs()
'-------------------------------------------------------------------------------
' Saves marked sheets as PDF file.
Const PDF_path = "C:\Reports"
Dim Snr As Integer
Dim Name As String
'Process all sheets in workbook
For Snr = 1 To ActiveWorkbook.Sheets.Count
Sheets(Snr).Activate
'Only print if A1 contains "Y"
If Cells(1, "A").Value <> "0" Then
Name = PDF_path & Snr & ActiveSheet.Name & Cells(1, "A").Value & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
Next Snr
End Sub
*I am also in process of moving to SharePoint (excel web) so obviously VBA doesn't work. My work around is to download any workbooks that I need to run this macro on to my desktop and then run the macro. I'm curious if there is any way to turn this into an office script and output to a specific document folder on SharePoint?