The problem with the code I have is that either it saves all the pages in all the worksheets in the workbook or it saves only the pages in the range specified by the "from" and "to" arguments.
The excel files I am working with have 7 worksheets, and each worksheet can have any amount of pages. If I specify that I want to export "from 1 to 4", for example, then only the first 4 pages of the first worksheet would be exported as a PDF document, not all the pages of the first 4 worksheets.
Can someone tell me how to achieve what I'm trying to do? The code below is not what I want:
application.ActiveWorkbook.ExportAsFixedFormat(
Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF,
path,
Excel.XlFixedFormatQuality.xlQualityStandard,
true,
true,
1,
4,
false,
Missing.Value);
End Sub
Call it by passing in a comma seperated list of sheets to export
Here's the answer: ActiveSheet.PageSetup.Pages.Count
If you use
ActiveSheet.ExportAsFixedFormat
after selecting multiple sheets I think it will do what you want (as long as your print areas are set up on each of the selected sheets).A raw recorded macro along those lines: