How do I save only tabs selected in a list box in a single pdf?

Dennis Psota 0 Reputation points
2025-05-20T15:56:24.25+00:00

I have a list box that contains the names of all the tabs in the Excel workbook and the following macro to do a print preview:

Sub print_sh()

Dim i As Long, c As Long

Dim SheetArray() As String

With ActiveSheet.ListBox1

For i = 0 To .ListCount - 1

If .Selected(i) Then

ReDim Preserve SheetArray(c)

SheetArray(c) = .List(i)

c = c + 1

End If

Next i

End With

Sheets(SheetArray()).PrintPreview

End Sub

But I cannot figure out how to create a macro to save the selected sheets as a single pdf.

Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,937 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Barry Schwarz 3,746 Reputation points
    2025-05-21T07:52:35.2366667+00:00

    What purpose is served by SheetArray? Could you not print immediately when Selected(i) is true?

    Consider building a new worksheet (possibly in a new workbook). When selected(i) is true, copy the contents of the selected worksheet into the new worksheet after any existing contents. You can then print this new worksheet as a single pdf.

    If you like, you can add some title information to the new worksheet before you copy each selected worksheet.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.