I am struggling with hiding sheets.
I used two sets of code:
Sub hidesheets()
Sheets("Materials - Specifications").Visible = False
Sheets("Fibre drop release sheet").Visible = False
End Sub
And next
Sub RAtoPDF()
Call hidesheets
Dim sh As Worksheet, sh2 As Worksheet
Dim ArraySheets() As String
Dim custom_name As String
Dim x As Variant
For Each sh In ActiveWorkbook.Worksheets
If sh.Tab.ColorIndex = 33 Then
'Sheets("Materials - Specifications").Visible = False
ReDim Preserve ArraySheets(x)
ArraySheets(x) = sh.Name
x = x + 1
End If
Next sh
Sheets(ArraySheets).Select
custom_name = "RA_" & ThisWorkbook.Name & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & custom_name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
Sheets("Frontsheet").Select
End Sub
I get:
Select method of sheets class failed
with debugger pointing to:
Sheets(ArraySheets).Select
I tried this line without an external macro, but the error is the same.
The XlVeryhidden
option also is not working.
Select method of sheets class failed means that you select a hidden sheet for printing
If sh.Tab.ColorIndex = 33 And sh.Visible = True Then