Solved

VB5 and Excel

Posted on 1999-01-22
3
297 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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