Reputation: 1083
I'M trying to print/export or save all my tabs in an excel workbook as one PDF document.
The number of tabs could be any number and could be named anything.
I have the following piece of code:
ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\tempo.pdf", Quality:= xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
But this obviously requires the number of sheets and the exact names of the sheets. Is there a way to maybe count the number of sheets in a workbook and print all of these to PDF as one PDF doc?
Please can someone show me how to do this? Thanks in advance
Upvotes: 1
Views: 3028
Reputation: 12499
Simply use ThisWorkbook.ExportAsFixedFormat or ActiveWorkbook.ExportAsFixedFormat
Option Explicit
Public Sub Example()
ThisWorkbook.ExportAsFixedFormat _
Type:=xlTypePDF, _
FileName:="C:\tempo.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
Workbook.ExportAsFixedFormat Method (Excel)
Upvotes: 1