Hi guys,
I have a userform where I can select the worksheets I want to print as pdf. I have saved the names in an array (SheetsToPrint). However, when I get to the line ThisWorkbook.Sheets(Array(SheetsToPrint)).Select, I get run time error 9.
Please help. Thank you in advance.
I have a userform where I can select the worksheets I want to print as pdf. I have saved the names in an array (SheetsToPrint). However, when I get to the line ThisWorkbook.Sheets(Array(SheetsToPrint)).Select, I get run time error 9.
Please help. Thank you in advance.
Rich (BB code):
Private Sub cmdOK_click()
Dim SheetsToPrint() As Variant
Dim ws As Worksheet
Dim LastRow As Integer, i As Integer
Dim x As Integer: x = 2
Dim y As Long: y = 0
Dim printSheets As Variant
Application.ScreenUpdating = False
Set ws = Worksheets("Lookup")
LastRow = Cells(ws.Rows.Count, "R").End(xlUp).Row
'loop through each check box and save
For i = 1 To 22
If Controls("CheckBox" & i).Value = True Then
ws.Cells(x, 19) = "Y"
y = y + 1
ReDim Preserve SheetsToPrint(y)
SheetsToPrint(y) = ws.Cells(x, 18)
Else
ws.Cells(x, 19) = "N"
End If
x = x + 1
Next i
ThisWorkbook.Sheets(Array(SheetsToPrint)).Select
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\Entry Form.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Sheets("Start Express Parcels").Select
Unload Me
Application.ScreenUpdating = True
End Sub