Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
failure to password protect file Dr Alok Modi MD Excel Discussion (Misc queries) 0 December 30th 08 01:56 PM
file/sendto/mailrecipient failure niuta Excel Discussion (Misc queries) 1 October 9th 05 10:32 AM
Save failure after VBA macro Macrophile05 Excel Programming 2 August 5th 05 02:45 PM
xls file failure lendapilot Excel Discussion (Misc queries) 5 January 17th 05 10:37 PM
save failure Ken Excel Programming 2 November 17th 03 07:25 PM


All times are GMT +1. The time now is 06:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"