Greetings!
I am wanting to use "cancel" within my macro that contains an "On Error GoTo". I would like for Sheet 68 M28 to have a 1 if the PDF has been created. A 22 if the PDF was not created due to an existing PDF with same name opened. And a 33 due to cancelling the PDF. I am using the following code, but cannot seem to get the cancel part to work.
Sub PDF_STAR_Cert()
Application.DisplayAlerts = False
If (Sheet1.Range("BF1371").Value) <> "17" Then
Range("W1").Select
Else
Application.Run ("Sheet_2_Unprotect")
Application.Run ("COPY_SOW_STARCert_FRAP")
Dim FileSelected As String
Dim Path As String
Dim x As String
x = Sheet14.Range("G78").Value
Sheet2.Visible = xlSheetVisible
Sheet68.Visible = xlSheetHidden
Sheets(Array("SOW_STAR")).Select
FileSelected = Application.GetSaveAsFilename(InitialFileName:=x, FileFilter:="PDF Files (*.pdf), *.pdf", Title:="Save PDF as")
On Error GoTo ClosePDF
ActiveWorkbook.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & FileSelected & ".pdf", OpenAfterPublish:=False
Sheet68.Range("M28").Value = 1 'PDF Created.
On Error GoTo 0
Sheet68.Visible = xlSheetVisible
Sheet2.Visible = xlSheetHidden
Sheet68.Range("M28").Value = 1 'PDF Created.
Sheet68.Select
Exit Sub
If Not FileSelected <> "False" Then
MsgBox "You have cancelled"
Sheet68.Visible = xlSheetVisible
Sheet2.Visible = xlSheetHidden
Sheet68.Range("M28").Value = 33 'PDF Not_Created due to Cancelling.
Sheet68.Select
Exit Sub
End If
Sheet68.Visible = xlSheetVisible
Sheet2.Visible = xlSheetHidden
Sheet68.Select
Application.DisplayAlerts = True
'*******************
'Error Handling Section
'*******************
ClosePDF:
STARCertPDF.Show
Sheet68.Visible = xlSheetVisible
Sheet68.Range("M28").Value = 22 'PDF Not_Created due to an existing PDF with same name opened.
Sheet2.Visible = xlSheetHidden
Sheet68.Select
End Sub
Bookmarks