Save multiple sheets to .pdf

calendar_today Asked Jan 18, 2013
thumb_up 34 upvotes
history Updated April 14, 2026

Direct Answer

Start by selecting the sheets you want to combine: ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).Select ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _…. This is a 6-line VBA Core snippet, ranked #15th of 95 by community upvote score, from 2013.


The Problem (Q-score 10, ranked #15th of 95 in the VBA Core archive)

The scenario as originally posted in 2013

I have a reporting spreadsheet that grabs some data from a database and forms three sheets of summary report information. I want to run the spreadsheet automatically from the command line, and have it automatically save all three reporting sheets as a PDF file(s).

At first I thought I could have a VBA macro on the sheet do this by a series of “print as PDF”, but that requires an intermediary interactive dialog box to specify the output file name. Then I find that I can just save as pdf, and the macro can set the output file name.
However this creates three separate files, and I have to then later put them together externally to merge them.

(It is odd that save as pdf only saves one sheet, where other save modes seem to save the entire workbook.)

Yes, there are tools for merging the three files later, but I want to know if there is some easy way to get Excel to save multiple sheets together as one pdf file.

I print now by a series of things like:

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, ...

Could I do instead a single statement something like (pseudo-code):

ThisWorkbook.Sheets(1,2,3,4).ExportAsFixedFormat Type:=xlTypePDF, ...

Why this Range / Worksheet targeting trips people up

The question centers on reaching a specific cell, range, or workbook object. In VBA Core, this is the #1 source of failures after activation events: every property (.Value, .Formula, .Address) behaves differently depending on whether the parent Workbook is explicit or implicit.


The Verified Solution — elite answer (top 10 %%) (+34)

6-line VBA Core pattern (copy-ready)

Start by selecting the sheets you want to combine:

ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).Select

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:tempo.pdf", Quality:= xlQualityStandard, IncludeDocProperties:=True, _
     IgnorePrintAreas:=False, OpenAfterPublish:=True


When to Use It — classic (2013–2016)

Ranked #15th in its category — specialized fit

This pattern sits in the 72% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the VBA Core archive for a higher-consensus alternative.

What changed between 2013 and 2026

The answer is 13 years old. The VBA Core object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.

help
Frequently Asked Questions

Why is this answer the top decile of VBA Core Q&A?
expand_more

Answer score +34 vs the VBA Core archive median ~11; this entry is elite. The score plus 10 supporting upvotes on the question itself (+10) means the asker and 33 subsequent voters all validated the approach.

Does the 6-line snippet run as-is in Office 2026?
expand_more

Yes. The 6-line pattern compiles on Office 365, Office 2024, and Office LTSC 2026. Verify two things: (a) references under Tools → References match those in the code, and (b) any Declare statements use PtrSafe on 64-bit Office.

Published around 2013 — what’s changed since?
expand_more

Published 2013, which is 13 year(s) before today’s Office 2026 build. The VBA Core object model has had no breaking changes in that window. Three things to re-test: (1) blocked macros on downloaded files (Mark-of-the-Web), (2) 64-bit API declarations (PtrSafe, LongPtr), (3) any shift toward Office Scripts for web scenarios.

Which VBA Core pattern ranks just above this one at #14?
expand_more

The pattern one rank above is “VBA – Excel : get rid of the case sensitivity when comparing words?”. If your use case overlaps, compare both before committing.

Data source: Community-verified Q&A snapshot. Q-score 10, Answer-score 34, original post 2013, ranked #15th of 95 in the VBA Core archive. Last regenerated April 14, 2026.

vba