Tanyaann1995
Board Regular
- Joined
- Mar 24, 2021
- Messages
- 62
- Office Version
- 2016
- Platform
- Windows
Hi,
I have created a userform where the user can pick which sheets they want to get printed by clicking on checkboxes. Once the user chooses which sheets they want to print, the code should print out only those sheets using an array. I have designed the code in such a way that if the user picks only certain sheets, the other array values become blank. I need to remove these empty values from the array to print out only the required sheets. Please help.
I have created a userform where the user can pick which sheets they want to get printed by clicking on checkboxes. Once the user chooses which sheets they want to print, the code should print out only those sheets using an array. I have designed the code in such a way that if the user picks only certain sheets, the other array values become blank. I need to remove these empty values from the array to print out only the required sheets. Please help.
VBA Code:
Sub print()
Dim PDFfile As String
Dim wksAllSheets() As Variant
Dim wksSheet1 As Worksheet
Dim wb As Workbook
Dim arr1, arr2, arr3, arr4
Set wb = ActiveWorkbook
UserForm5.Show
If UserForm5.CheckBox1.Value = True Then
arr1 = Array("Cover")
Else
arr1 = Array("")
End If
If UserForm5.CheckBox2.Value = True Then
arr2 = Array("Revision")
Else
arr2 = Array("")
End If
If UserForm5.CheckBox5.Value = True Then
arr3 = Array("Emerson COMMERCIAL OFFER")
Else
arr3 = Array("")
End If
If UserForm5.CheckBox4.Value = True Then
arr4 = Array("Technical Offer")
Else
arr4 = Array("")
End If
wksAllSheets = uniqueArr(arr1, arr2, arr3, arr4)
PDFfile = wb.path & "\" & wb.Worksheets(1).Range("F12").Value & ".pdf"
wb.Sheets(wksAllSheets).Select
Set wksSheet1 = wb.Sheets("Cover")
wksSheet1.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=PDFfile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
wb.Worksheets(1).Select
End Sub