lesleyfayburton
New Member
- Joined
- Dec 4, 2020
- Messages
- 8
- Office Version
- 2016
I tried to use the beginning of one script and add to it, but it's not working. When I am saving the file I want it to check to see if it already exists and if so the user can overwrite or save the new version (which will add a number from the cell range). Then close it out if it can't be saved. Any help you can offer I would appreciate it.
'Test to see if file name already exists
If Len(Dir(saveLocation & "\" & fName)) > 0 Then
If MsgBox(MsgBox("This ticket already exists, if you want to overwrite click Yes, if not, click No and a new version will be saved?", vbQuestion + vbYesNo)_
If answer = vbYes Then
rng.ExportAsFixedFormat Type:=xlTypePDF, FileName:=SaveAsStr, Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False
MsgBox "Yes" & SaveAsStr = saveLocation & "\" & fName
Else
MsgBox "No" & SaveAsStr = SaveAsStr = saveLocation & "\" & fName & Sheets("Trade Ticket").Range("Z1")
rng.ExportAsFixedFormat Type:=xlTypePDF, FileName:=SaveAsStr, Quality:=xlQualityStandard, In
cludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
'Error Handler
NotSavedYet:
MsgBox "This file has not been initially saved. " & _
"Cannot save a new version!", vbCritical, "Not Saved To Computer"
End If
End Sub
'Test to see if file name already exists
If Len(Dir(saveLocation & "\" & fName)) > 0 Then
If MsgBox(MsgBox("This ticket already exists, if you want to overwrite click Yes, if not, click No and a new version will be saved?", vbQuestion + vbYesNo)_
If answer = vbYes Then
rng.ExportAsFixedFormat Type:=xlTypePDF, FileName:=SaveAsStr, Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False
MsgBox "Yes" & SaveAsStr = saveLocation & "\" & fName
Else
MsgBox "No" & SaveAsStr = SaveAsStr = saveLocation & "\" & fName & Sheets("Trade Ticket").Range("Z1")
rng.ExportAsFixedFormat Type:=xlTypePDF, FileName:=SaveAsStr, Quality:=xlQualityStandard, In
VBA Code:
End If
'Error Handler
NotSavedYet:
MsgBox "This file has not been initially saved. " & _
"Cannot save a new version!", vbCritical, "Not Saved To Computer"
End If
End Sub