Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Save As Then Replace Bombs Out

Thanks Vergel! Definitely looks like it will work; will give it a go....have
a great evening, and thanks again for your help.

"Vergel Adriano" wrote:

You can check for file existence before calling the SaveAs. Something like
this:

Do
fname = Application.GetSaveAsFilename(InitialFileName:="",
FileFilter:="Microsoft Excel Workbook (*.xls), *.xls")
If fname < False Then
'check if file exists
If Dir(fname) < "" Then
'File exists. Ask if okay to replace
If vbYes < MsgBox("File already exists. Do you want to replace
it?", vbYesNo) Then
'not ok to replace, set fname to False
fname = False
End If
End If
End If
Loop Until fname < False

ActiveWorkbook.SaveAs Filename:=fname, FileFormat:=xlWorkbookNormal


--
Hope that helps.

Vergel Adriano


"Paige" wrote:

When I bring up the saveas menu, if someone selects an existing file and hits
Save, they then get the warning message saying the file already exists and do
they want to replace it. If they hit 'No' or 'Cancel', then the code errors
out. How do I fix this? I still want them to get the warning message, but
if they select 'No' or 'Cancel', the message should disappear and take them
back to the saveas menu so they can select another file or enter a new file
name. The current code I'm using is:

Do
FName = Application.GetSaveAsFilename(InitialFileName:="",
FileFilter:="Microsoft Excel Workbook (*.xls), *.xls")
Loop Until FName < False
ActiveWorkbook.SaveAs Filename:=FName, FileFormat:=xlWorkbookNormal

Appreciate any help I can get on this; thanks....

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
Code Bombs in Excel 2007 Chaplain Doug Excel Programming 6 February 7th 07 06:34 PM
Excel bombs out in macro...help please!! SanFranGuy06 Excel Programming 5 May 11th 06 05:32 PM
Code bombs at line indicated, why? Jim May Excel Programming 3 September 15th 05 11:37 PM
sumproduct bombs out JN Excel Worksheet Functions 15 July 11th 05 11:50 PM
Macro runs in Excel 2003, bombs in XP - Compatability question Harry[_8_] Excel Programming 3 March 3rd 05 08:40 AM


All times are GMT +1. The time now is 08:52 AM.

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

About Us

"It's about Microsoft Excel"