Currently I am saving a PDF to a folder and it looks to see if that file had already been saved to that folder. If that file exists it asks if you would like to overwrite. The Problem I have is if you enter anything other 'Y' it will create the new file : How would I add that if they choose to hit cancel then it cancels?
Yes = Overwrite file / No = Makes the new time stamped file already in code/ Cancel = Exits entirely.
Also, this is the big issue
If the user chooses to overwrite the PDF and by chance the user had that PDF open you get a runtime error because the file is open until the user manually closes the file.
Is it possible that after it knows the file exists and it prompts if you want to overwrite & if you choose overwrite then it makes sure the PDF is closed so it can overwrite eliminating the user from having to close the file manually
If it can't close automatically then could is show message box that says "the PDF seams to be open can not overwrite please close PDF and rerun." then exit
That way they would not get the run-time error saying could not save..... People see run time error and automatically stop trying
Sub Covercopypaste()
Range("A1:k46").Select
ThisWorkbook.Save
Selection.Copy
Call PDfExist
End Sub
Sub PDfExist()
MyPath = ActiveWorkbook.Path & "\Morning Reports\"
fn = "Morning Report" & "_" & Format(Now(), "mm.dd.yy") & ".PDF"
Fname = MyPath & fn
FileInQuestion = Dir(Fname)
If FileInQuestion <> "" Then
If InputBox("Today's PDF Exists, Want to overwrite (Y/N)? If 'No' an Additional PDF With Time Stamp Will be added to Folder. ") <> "y" Then
fn = "Morning Report" & "_" & Format(Now(), "mm.dd.yy hhmm") & ".PDF"
Fname = MyPath & fn
End If
End If
Sheets("Morning Report").Range("A1:k46").ExportAsFixedFormat Type:=xlTypePDF, FileName:=Fname, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
Bookmarks