mtagliaferri
Board Regular
- Joined
- Oct 27, 2004
- Messages
- 156
The below code is working, however once it has run and the pdf files are open, if the code is run again will display error '-2147018887 (80071779)'
I am trying to solve this by handling the error and display the message to close the documents.
All sheets are hidden with the exclusion of the main one named Dashboard, for some reason when the handle errorhandle runs, when clicking on OK on the error message the first sheet from the code (AcceptanceOfResignation) becomes visible and selected.
How can I handle this error in a way that when acknowledging the error message by the user it returns to the Dashboard sheet and all other sheets remain invisible?
I am trying to solve this by handling the error and display the message to close the documents.
All sheets are hidden with the exclusion of the main one named Dashboard, for some reason when the handle errorhandle runs, when clicking on OK on the error message the first sheet from the code (AcceptanceOfResignation) becomes visible and selected.
How can I handle this error in a way that when acknowledging the error message by the user it returns to the Dashboard sheet and all other sheets remain invisible?
VBA Code:
Sub CreateOpenPDF()
Application.ScreenUpdating = False
On Error GoTo ErrorHandle
ShAcceptanceOfResignation.Visible = True
With ShAcceptanceOfResignation
.ExportAsFixedFormat xlTypePDF, Environ("Userprofile") & "\Documents\" & .Range("B16") & " " & .Range("B17") & " " & _
Format(.Range("M26"), "YYYYMMDD") & " " & .Name & ".pdf", OpenAfterPublish:=True
ShAcceptanceOfResignation.Visible = False
End With
ShLeaversForm.Visible = True
With ShLeaversForm
.ExportAsFixedFormat xlTypePDF, Environ("Userprofile") & "\Documents\" & .Range("D12") & " " & .Range("D13") & " " & _
Format(.Range("E19"), "YYYYMMDD") & " " & .Name & ".pdf", OpenAfterPublish:=True
ShLeaversForm.Visible = False
End With
ShCompanyPropertyChecklist.Visible = True
With ShCompanyPropertyChecklist
.ExportAsFixedFormat xlTypePDF, Environ("Userprofile") & "\Documents\" & .Range("D11") & " " & .Range("D12") & " " & _
Format(.Range("J13"), "YYYYMMDD") & " " & .Name & ".pdf", OpenAfterPublish:=True
ShCompanyPropertyChecklist.Visible = False
End With
ErrorHandle:
Select Case Err.Number
Case -2147018887
MsgBox "Please close all created documents that are open before creating new ones"
Case Else
Exit Sub
End Select
Application.ScreenUpdating = True
End Sub