?
Solved

VB5 and Excel

Posted on 1999-01-22
3
Medium Priority
?
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 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…
Suggested Courses

777 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