Print multiple hidden worksheets but save as single file

pwb100

New Member
Joined
May 12, 2023
Messages
16
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I came across the following vba code to print hidden worksheets - many thanks @Fluff . I would like to print hidden worksheets as one file (of the worksheets within the specified range) rather than an individual file per worksheet.

VBA Code:
Sub Print_Hidden()
   Dim Sht As Worksheet
   Application.ScreenUpdating = False
   For Each Sht In Sheets(Array("Weld", "Composite", "Rubber"))
      Sht.Visible = True
      Sht.PrintOut Copies:=1, Collate:=True
      Sht.Visible = False
   Next Sht
   Application.ScreenUpdating = True
End Sub
 
So it is simply printing all the hidden sheets where the value in Cell J3 > 0 (zero) into a single PDF file?
And please again, don't create more clutter then we already have. No need quoting a post just above it (Post #19 quoted in Post #29!!!!!). If you need to refer to a post, use the post number.

Just to make things as easy as possible, are there any hidden sheets that are not part of this checking?
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Ahh sorry - I just pressed the reply button at the bottom of your last post and it automatically added the quote from it. I will delete in future.

To answer your question - yes there are other hidden sheets that are not part of the checking. They are sheets that I hide to prevent staff tampering with things. It is only those sheets, F1-F33, that need to be checked and exported.
 
Upvote 0
I've gone way overboard here but it should, I hope, solve all the problems previously encountered.
The saveNm line is where the name for the PDF file to be saved is. Change both, sheet name and cell address, as needed.
Code will unhide all the hidden worksheets and put their names in an array.
It'll then check if the Value of these sheets in cell J3 is more than 0 (zero)
If so, these sheet names are put into a string and later converted to an array
These sheets are then saved as a PDF file and names as saveNm
Finally, the sheets are hidden again.
Code:
Sub SavePDF_New_3()
Dim saveNm As String, sh As Worksheet, i As Long, j As Long, shtArr1, shtArr2
saveNm = Sheets("Sheet1 (F2)").Range("A3").Value   '<---- Change sheet name and range as required.
Application.ScreenUpdating = False

For Each sh In ThisWorkbook.Worksheets
    If sh.Visible = False Then
        sh.Visible = True
        shtArr1 = shtArr1 & "|" & sh.Name
    End If
Next sh
shtArr1 = Split(Mid(shtArr1, 2), "|")

For i = LBound(shtArr1) To UBound(shtArr1)
    If Left(shtArr1(i), 9) = "Sheet1 (F" Then
        If Sheets(shtArr1(i)).Range("J3").Value > 0 Then shtArr2 = shtArr2 & "|" & shtArr1(i)
    End If
Next i
shtArr2 = Split(Mid(shtArr2, 2), "|")

Sheets(shtArr2).Copy
    With ActiveWorkbook
        .ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\" & saveNm & ".pdf", OpenAfterPublish:=True
        .Close False
    End With
    
For j = LBound(shtArr1) To UBound(shtArr1)
    Sheets(shtArr1(j)).Visible = False
Next j
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution
Many, many thanks @jolivanes for all your support with this. The sheets now do exactly as I had visioned. Your help is very much appreciated.
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,375
Members
449,155
Latest member
ravioli44

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