I have this macro I made that converts the excel page to .pdf and then saves it to a folder I assigned. the macro works and the file is saved in the right folder but after the macro runs it displays the message "could not create PDF file" which is the message that is supposed to be displayed if there were any issues. I really don't think I need the errhandler parts but I'm not totally sure on that part. However if I delete the errhandler stuff no message would be displayed at all. I also wanted to add a piece of code that when the user clicks the ok button after the message is displayed the excel workbook closes without saving but that part is not as important. See VBA below. Any help would be appreciated.
Option Explicit
Sub PDFActiveSheet()
Dim wsa As Workbook
Dim Key As Variant
Dim MyFile As Variant
Set Key = ActiveWorkbook.Names("Key_Primary").RefersToRange
On Error GoTo errHandler
ActiveSheet.ExportAsFixedFormat xlTypePDF, "C:\Users\brian_williams\Desktop\KPI Project\Submitted Audits" & Key & ".pdf", , , False
If MyFile <> "False" Then
wsa.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=MyFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
MsgBox " Audit has been Submitted and you can close this form. Thank You!"" _
& vbCrLf _
& MyFile
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub
Option Explicit
Sub PDFActiveSheet()
Dim wsa As Workbook
Dim Key As Variant
Dim MyFile As Variant
Set Key = ActiveWorkbook.Names("Key_Primary").RefersToRange
On Error GoTo errHandler
ActiveSheet.ExportAsFixedFormat xlTypePDF, "C:\Users\brian_williams\Desktop\KPI Project\Submitted Audits" & Key & ".pdf", , , False
If MyFile <> "False" Then
wsa.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=MyFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
MsgBox " Audit has been Submitted and you can close this form. Thank You!"" _
& vbCrLf _
& MyFile
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub