Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Using SaveAs Statement to overwrite existing File

Hi

I recently coded a spreadsheet which creates subsets of
data which are then saved separately. After cutting the
data I use the statement below to save the data:

ActiveWorkbook.SaveAs Filename:="D:\msoffice\access\work\"
& thisfilename & ".xls", _
FileFormat:=xlNormal, Password:="",
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close

However, the problem I have is that excel keeps stopping
at this command to get confirmation that it's okay to
overwrite an existing file with the same name with the new
one.

is there anything I can put in the code that effectively
stops excel checking to see if the filename already exists?

Thanks in advance for any postings.

Peter
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Using SaveAs Statement to overwrite existing File

I put this line in to test for the existence of the new file before saving.

If Dir("D:\msoffice\access\work\" & thisfilename & ".xls") = "" Then
Kill("D:\msoffice\access\work\" & thisfilename & ".xls")
End if

You may also think about trapping error 70 (? or 75? from memory) to handle the situation where another user already has the file open that you are trying to Kill.

"Peter" wrote:

Hi

I recently coded a spreadsheet which creates subsets of
data which are then saved separately. After cutting the
data I use the statement below to save the data:

ActiveWorkbook.SaveAs Filename:="D:\msoffice\access\work\"
& thisfilename & ".xls", _
FileFormat:=xlNormal, Password:="",
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close

However, the problem I have is that excel keeps stopping
at this command to get confirmation that it's okay to
overwrite an existing file with the same name with the new
one.

is there anything I can put in the code that effectively
stops excel checking to see if the filename already exists?

Thanks in advance for any postings.

Peter

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using SaveAs Statement to overwrite existing File

wouldn't the check be

If Dir("D:\msoffice\access\work\" & thisfilename & ".xls") < "" Then
Kill("D:\msoffice\access\work\" & thisfilename & ".xls")
End if

--
Regards,
Tom Ogilvy

"Trevor Mills" wrote in message
...
I put this line in to test for the existence of the new file before

saving.

If Dir("D:\msoffice\access\work\" & thisfilename & ".xls") = "" Then
Kill("D:\msoffice\access\work\" & thisfilename & ".xls")
End if

You may also think about trapping error 70 (? or 75? from memory) to

handle the situation where another user already has the file open that you
are trying to Kill.

"Peter" wrote:

Hi

I recently coded a spreadsheet which creates subsets of
data which are then saved separately. After cutting the
data I use the statement below to save the data:

ActiveWorkbook.SaveAs Filename:="D:\msoffice\access\work\"
& thisfilename & ".xls", _
FileFormat:=xlNormal, Password:="",
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close

However, the problem I have is that excel keeps stopping
at this command to get confirmation that it's okay to
overwrite an existing file with the same name with the new
one.

is there anything I can put in the code that effectively
stops excel checking to see if the filename already exists?

Thanks in advance for any postings.

Peter



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using SaveAs Statement to overwrite existing File

Another approach:

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
"D:\msoffice\access\work\" _
& thisfilename & ".xls", _
FileFormat:=xlNormal, Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False
Application.DisplayAlerts = True
ActiveWorkbook.Close SaveChanges:=False


--
Regards,
Tom Ogilvy


"Peter" wrote in message
...
Hi

I recently coded a spreadsheet which creates subsets of
data which are then saved separately. After cutting the
data I use the statement below to save the data:

ActiveWorkbook.SaveAs Filename:="D:\msoffice\access\work\"
& thisfilename & ".xls", _
FileFormat:=xlNormal, Password:="",
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close

However, the problem I have is that excel keeps stopping
at this command to get confirmation that it's okay to
overwrite an existing file with the same name with the new
one.

is there anything I can put in the code that effectively
stops excel checking to see if the filename already exists?

Thanks in advance for any postings.

Peter



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
Merged Workbooks Overwrite existing text Puzzled user Excel Discussion (Misc queries) 0 July 10th 08 05:08 PM
ODBC Overwrite existing cells cdobbs Excel Discussion (Misc queries) 0 February 11th 07 05:40 AM
accidentally click YES to overwrite an existing file mtrent Excel Discussion (Misc queries) 2 March 30th 06 07:01 PM
Q: overwrite during saveas JIM.H. Excel Discussion (Misc queries) 1 January 5th 05 07:27 PM
overwrite Excel SaveAs function from File menu susie Excel Programming 1 July 31st 03 04:47 AM


All times are GMT +1. The time now is 10:11 PM.

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"