Solved

VB5 and Excel

Posted on 1999-01-22
3
296 Views
Last Modified: 2010-07-27
I have created an excel object from VB.  I write data to the spreadsheet object and before I close the app I would like to save the workbook.  I am using the commondialog control to set the filename and path and then using workbook.saveas(commondialog.filename).  The problem is if the filename I am using already exists in the path that I have selected then excel brings up the dialog that asks if you want to save over the existing file. If you answer NO then I get a runtime error 1004 "method saveas of object workbook failed".  

Can anyone give me a solution or a way to check if the file exists before the workbook.saveas call?
0
Comment
Question by:gemme
  • 2
3 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 100 total points
ID: 1470180
You can use the Dir$ function to check if the file already exists or use the Kill function to destroy it.

Maybe a good solution would be to destroy (without checking if the file already exists) and then save your workbook:

on error resume next
kill "c:\file.xls"
on error goto 0
workbook.saveas "c:\file.xls"
 
0
 

Author Comment

by:gemme
ID: 1470181
is there a way to do this from the excel dialogs?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 1470182
You can use the same code in an Excel module but not in dialogs!
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question