I have a main form (I guess I could call it so), that exports Excel sheets to PDFs. I want to have a checkbox that allows users to open the PDF file after run if it's checked. At the moment, when the checkbox is clicked, it tries to run the checkbox macro, but if it's not checked, it returns an error. This is the code:
Sub CheckBox5_Click()
Dim ws As Worksheet
Dim chckBox As CheckBox
Set chckBox = Sheets("CompileSheet").CheckBoxes("CheckBox5")
Set ws = ThisWorkbook.Sheets("Sheet2")
If chckBox.Value = 1 Then
ws.ExportAsFixedFormat Type:=xlTypePDF, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
OpenAfterPublish:=True
Else
ws.ExportAsFixedFormat Type:=xlTypePDF, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
OpenAfterPublish:=False
End If
End Sub
Don't hesitate to ask for clarification. Thanks.