Selecting sheets based on values to print as one PDF

firemanli

New Member
Joined
Apr 11, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Good day,
I have a workbook with multiple sheets in it.
On a Control Sheet, I have the following data:

Sheet NamePrint?
Cover SheetPrint
DetailsPrint
WorksheetNo
ST-124Print
Terms & ConditionsPrint

I want a print button that will print one pdf file of all the sheets that are selected by the control sheet.

Thanks
Aaron
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi
Based on an answer to a similar question, try the code below. I assigned a range name 'ControlPanel' to the table in your example.
HTH
Martin

VBA Code:
Dim strSheets As String
Dim i As Integer
Dim rngControl As Range
'Define the range object
Set rngControl = ThisWorkbook.Names("ControlPanel").RefersToRange
'Loop through the rows of the range
For i = 1 To rngControl.Rows.Count Step 1
    'Only where Print? column = 'Print'
    If StrComp(rngControl.Cells(i, 2).Value, "Print", vbTextCompare) = 0 Then
        'Append comma for all but first row
        If Len(strSheets) > 0 Then
            strSheets = strSheets & ","
        End If
        'Append sheet name
        strSheets = strSheets & rngControl.Cells(i, 1).Value
    End If
Next i
'Copy selected sheets to a new workbook
Sheets(Split(strSheets, ",")).Copy
'Export to PDF
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Temp\FileOutput.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=False
'Close the workbook
ActiveWorkbook.Close SaveChanges:=False
 
Upvote 0

Forum statistics

Threads
1,215,081
Messages
6,123,016
Members
449,093
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top