Good Friday Morning, Gurus.
I wrote a simple code to automatically save a workbook as a temp file when opened, so as not to corrupt the original data. I added an error handler so that if someone was working with the temp file, and it was already open when someone tried to save another temp file, it would save as temp2. As further precaution, I added temp3 and temp4, in case someone still had both 1 and 2 open. (Following me?)
Here's the problem. The original temp file saves fine. If I leave it open, and try to save another, temp2 saves fine. If, however, I have both temp and temp2 open, I get the error "can't save as the same filename...."
Why does my code below not skip to file3 when it encounters this error?
Here's the code:
Sub Save_As_Temp()
On Error GoTo file2
Application.DisplayAlerts = False
ActiveSheet.Shapes("Button 2").Delete
ActiveWorkbook.SaveAs Filename:="M:\PO Response Tracking - Temp.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
MsgBox "Your file has been saved as M:\PO Response Tracking - Temp.xls"
Exit Sub
file2:
On Error GoTo file3
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="M:\PO Response Tracking - Temp2.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
MsgBox "Your file has been saved as M:\PO Response Tracking - Temp2.xls"
Exit Sub
file3:
On Error GoTo file4
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="M:\PO Response Tracking - Temp3.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
MsgBox "Your file has been saved as M:\PO Response Tracking - Temp3.xls"
Exit Sub
file4:
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="M:\PO Response Tracking - Temp4.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
MsgBox "Your file has been saved as M:\PO Response Tracking - Temp4.xls"
End Sub
Thanks in advance.
Hutch
Bookmarks