Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Failure at File Save
I am doing a file save as, per the code below.
Dim fName as Variant Do fName = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:="Microsoft Excel Workbook (*.xls), *.xls") Loop Until fName < False ActiveWorkbook.SaveAs Filename:=fName, FileFormat:=xlWorkbookNormal It works fine if the user types in a new file name and saves, or if the user selects an existing file and elects to replace the existing file with the new one. However, it doesn't work in the following scenario: User selects an existing filename and hits 'Save'; a dialog box comes up that says "File name already exists...do you want to replace it?", with the options of 'Yes', 'No', and 'Cancel'. If the user selects either 'Cancel' or 'No' on the dialog (versus 'Yes'), it gives a run-time 1004 error: Method 'Save as' of '_Workbook' failed and goes to the last line of my code above. I can't figure out how to capture these two scenarios ('Cancel' or 'No'). If they select 'Cancel' or 'No', it just needs to go back to the saveas dialog box. Can someone assist me with this please? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Failure at File Save
Dim fName as Variant
again: Do fName = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:="Microsoft Excel Workbook (*.xls), *.xls") Loop Until fName < False On error Resume next ActiveWorkbook.SaveAs Filename:=fName, FileFormat:=xlWorkbookNormal On Error goto 0 if ActiveWorkbook.FullName < fName then goto again -- Regards, Tom Ogilvy "Paige" wrote: I am doing a file save as, per the code below. Dim fName as Variant Do fName = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:="Microsoft Excel Workbook (*.xls), *.xls") Loop Until fName < False ActiveWorkbook.SaveAs Filename:=fName, FileFormat:=xlWorkbookNormal It works fine if the user types in a new file name and saves, or if the user selects an existing file and elects to replace the existing file with the new one. However, it doesn't work in the following scenario: User selects an existing filename and hits 'Save'; a dialog box comes up that says "File name already exists...do you want to replace it?", with the options of 'Yes', 'No', and 'Cancel'. If the user selects either 'Cancel' or 'No' on the dialog (versus 'Yes'), it gives a run-time 1004 error: Method 'Save as' of '_Workbook' failed and goes to the last line of my code above. I can't figure out how to capture these two scenarios ('Cancel' or 'No'). If they select 'Cancel' or 'No', it just needs to go back to the saveas dialog box. Can someone assist me with this please? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
failure to password protect file | Excel Discussion (Misc queries) | |||
file/sendto/mailrecipient failure | Excel Discussion (Misc queries) | |||
Save failure after VBA macro | Excel Programming | |||
xls file failure | Excel Discussion (Misc queries) | |||
save failure | Excel Programming |