I have this VBA that prints some sheets from one workbook to PDF. It works perfectly
But I need a VBA code that prints selected sheets from 2 different workbooks to one pdf file.
Here is the current code I have
And here is what I am testing. but this code only prints the worksheets from the second file. I want all sheets to be printed on the same one PDF
But I need a VBA code that prints selected sheets from 2 different workbooks to one pdf file.
Here is the current code I have
Code:
Sub PrintPDF()
Dim saveDIR As String
Dim mydate As Date
mydate = Sheets("New England Balances").Range("x2").Value
On Error Resume Next
saveDIR = "C:\Daily PDF Files\New England Gas Fundamentals"
Sheets(Array("Chart1", "Chart2", "Chart3", "Chart4", "LDCs MA1", "LDCs MA2", "Elec Gen MA", "LDCs RI", "Elec Gen RI", "LDCs ME", "Elec Gen ME", "LDCs NH", "Elec Gen NH", "LDCs CT", "Elec Gen CT")).Select
ChDir _
"C:\Daily PDF Files"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Daily PDF Files\" & "New England Gas Fundamentals_" & VBA.Format(mydate, "MMDDYYYY") & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
End Sub
And here is what I am testing. but this code only prints the worksheets from the second file. I want all sheets to be printed on the same one PDF
Code:
Sub PrintPDFtest()
Dim saveDIR As String
Dim mydate As Date
mydate = Sheets("New England Balances").Range("x2").Value
On Error Resume Next
saveDIR = "C:\Daily PDF Files\New England Gas Fundamentals"
Sheets(Array("Chart1", "Chart2", "Chart3", "Chart4", "LDCs MA1", "LDCs MA2", "Elec Gen MA", "LDCs RI", "Elec Gen RI", "LDCs ME", "Elec Gen ME", "LDCs NH", "Elec Gen NH", "LDCs CT", "Elec Gen CT")).Select
Workbooks.Open Filename:= _
"C:\test\Templates for Report content_test_v12AB1.xltm", UpdateLinks:=0
Sheets(Array("Chart1", "Chart2", "Chart3", "Chart4", "Chart5", "Chart6", "Chart7", "Chart8")).Select
ChDir _
"C:\Daily PDF Files"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Daily PDF Files\" & "New England Gas Fundamentals_" & VBA.Format(mydate, "MMDDYYYY") & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
End Sub
Last edited by a moderator: