Hi,
I have the following code which saves the sheet as a PDF in a particular folder. It works as desired. I need some code to add to this which will check the folder to see if the PDF already exists. It should produce an overwrite warning if it does and ask the user if they would like to continue or not.
I have the following code which saves the sheet as a PDF in a particular folder. It works as desired. I need some code to add to this which will check the folder to see if the PDF already exists. It should produce an overwrite warning if it does and ask the user if they would like to continue or not.
VBA Code:
Select Case MsgBox("Is the date and shift type correct?", vbYesNo Or vbQuestion, Application.Name)
Case vbNo
Debug.Print "User exit"
Exit Sub
End Select
Dim SharePointPath As String
Dim PdfFileName As String
Dim msg As String
On Error GoTo SaveError
SharePointPath = "FOLDER"
PdfFileName = Replace(Range("D6").Value, "/", "") & ActiveSheet.Range("J6").Value
If Worksheets("Mechanics").Range("B15").Value = True Then
Call DarkMode
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=SharePointPath & PdfFileName, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Call DarkMode
Else
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=SharePointPath & PdfFileName, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
msg = "Handover saved. You can now close the spreadsheet."
MsgBox msg, vbInformation, "Upload Successful"
Exit Sub
SaveError:
msg = "Handover not saved. Please contact X on e-mail and use the backup document for today." & vbCr & vbCr & Err.Number & " - " & Err.Description
MsgBox msg, vbCritical, "Upload Failure"
End Sub