SaveAs error handling

G

Guest

Here is the problem...I tell the workbook where to save and with what name
using code, part of the file name is a date entered by the user. If the user
enters the same date then I want to give them the option of overwriting the
file or canceling the save. I have tried the following code and can't get it
to work properly. It works great if I put in Application.DisplayAlerts =
False and just allow it to overwrite the existing file, but if there is
already a lot of info in that file that would not be good. I would like it to
be a critical message and they can either choose yes or no, if they choose
yes then it would resume the save, if no then I will put some code in so that
certain sheets are shown. Any help is greatly appreciated.

On Error GoTo SaveOrNot

ActiveWorkbook.SaveAs Filename:= _
myFileName, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

MsgBox "File Saved to " & myFileName
End If
Application.ScreenUpdating = True

SaveOrNot:
Dim Res As Long
Res = MsgBox("A File With This Name Already Exists In This Location! Do You
Want To Replace It?", vbYesNo)
If Res = 6 Then
Resume
ElseIf Res = 7 Then
End If
End Sub
 
D

Die_Another_Day

how 'bout this:
If Len(Dir(MyFileName)) > 0 Then
'File already exists Insert msgbox code here
Else
'File does not exist. Insert save code here
End If

HTH

Charles Chickering
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Simplify save code 11
Rename rather than overwrite existing file 4
Two digit dates and two digit days 3
File Exist 8
SaveAs to existing file 5
File SaveAs 1
Hiding an Excel file using VBA 1
Result code for SaveAs 4

Top