Solved

VB5 and Excel

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

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 69

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now