Below is some code to print the active sheet to a PDF, works great. The issue is if the user leaves the PDF viewer open and clicks to print again I get an error, see below. Can anyone help with stopping the macro from running to prevent an accidental error?
Capture.PNG
Private Sub CommandButton2_Click()
Dim strDesktop As String
strDesktop = CreateObject("WScript.Shell").SpecialFolders("Desktop")
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=strDesktop & "\SHIPPING REPORT " & Format(Date, "mm.dd.yyy") & ".pdf", openafterpublish:=True
MsgBox "SHIPPING REPORT PRINTED", vbInformation, "HUNTWOOD CABINETS"
End Sub
Bookmarks