Hi, I have the below code which works great. I want to add a section so that it will check whether the PDF already exists in the given SharePoint folder (an overwrite warning essentially). A popup box should come up if the file already exists and the user can either click yes or no to overwrite, and then the rest of the code should work as already programmed.
Note that a team of colleagues use this spreadsheet via SharePoint. Everyone has linked the SharePoint folder with their individual OneDrive, and therefore we all access the spreadsheet via our individual OneDrives in My Files. Everything syncs with SharePoint and works great, I just need to add the above additional section into the code.
Note that a team of colleagues use this spreadsheet via SharePoint. Everyone has linked the SharePoint folder with their individual OneDrive, and therefore we all access the spreadsheet via our individual OneDrives in My Files. Everything syncs with SharePoint and works great, I just need to add the above additional section into the code.
VBA Code:
Sub SaveAsPDF()
'
' SaveAsPDF Macro
'
' Keyboard Shortcut: Ctrl+Shift+S
'
Select Case MsgBox("Have you checked the date and shift are 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 = "https://company.sharepoint.com/examplefolder/" '<<<<<<<<<<<< edit as required.
PdfFileName = Replace(Range("D6").Value, "/", "") & ActiveSheet.Range("J6").Value
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=SharePointPath & PdfFileName, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
msg = "Handover successfully uploaded to SharePoint."
MsgBox msg, vbInformation, "Upload Successful"
Exit Sub
SaveError:
msg = "Handover was not uploaded to SharePoint. 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