PC Review


Reply
Thread Tools Rate Thread

Routine for checking if file exists

 
 
Centurion
Guest
Posts: n/a
 
      26th Jan 2005
Hello,
I am using Excel 97, and have written (by recording keystrokes)
a macro that does several things and finishes off by saving the file.
However if the saved file already exists it stops the macro and prompts
user if it's ok to overwrite the file.

I would like to........

1) how do I test (within VBA) to see if the file exists.

2) If the file does exist, then overwrite without prompt.
Or alternately, save file and incrementally add '1'
to the end of the subsequent file.

Example
File-01
File-02
File-03


Thanks in anticipation.

--
Centurion


 
Reply With Quote
 
 
 
 
=?Utf-8?B?YmVu?=
Guest
Posts: n/a
 
      26th Jan 2005
several ways
you could use the
Kill
command to kill the file first
and then save it so that there is no file by that name
you will get an error on the Kill command if the file does not exist, but
you can use
On error resume next
to skip the error. Look up in help index on the KILL method.
Warning. This will permantly delete any file you use it on without asking,
and can delete entire folders!

"Centurion" wrote:

> Hello,
> I am using Excel 97, and have written (by recording keystrokes)
> a macro that does several things and finishes off by saving the file.
> However if the saved file already exists it stops the macro and prompts
> user if it's ok to overwrite the file.
>
> I would like to........
>
> 1) how do I test (within VBA) to see if the file exists.
>
> 2) If the file does exist, then overwrite without prompt.
> Or alternately, save file and incrementally add '1'
> to the end of the subsequent file.
>
> Example
> File-01
> File-02
> File-03
>
>
> Thanks in anticipation.
>
> --
> Centurion
>
>
>

 
Reply With Quote
 
 
 
 
Chip
Guest
Posts: n/a
 
      26th Jan 2005
I could help you with either of those options, but another option is
simply to have it not say that prompt...it could just save over if it
exists, or save it as a new file if it doesnt-all without
asking...would that be better for you?

 
Reply With Quote
 
=?Utf-8?B?YmVu?=
Guest
Posts: n/a
 
      26th Jan 2005
I have always thought there was a way to do that. How do you ahve it
overwrite without asking? because Application.Displayalerts = False has
never worked for me

"Chip" wrote:

> I could help you with either of those options, but another option is
> simply to have it not say that prompt...it could just save over if it
> exists, or save it as a new file if it doesnt-all without
> asking...would that be better for you?
>
>

 
Reply With Quote
 
Centurion
Guest
Posts: n/a
 
      26th Jan 2005
"Chip" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I could help you with either of those options, but another option is
> simply to have it not say that prompt...it could just save over if it
> exists, or save it as a new file if it doesnt-all without
> asking...would that be better for you?
>


Yes, how do I do that.

--
Centurion


 
Reply With Quote
 
Chip
Guest
Posts: n/a
 
      26th Jan 2005
Hmm..that is odd..it has always worked for me...can you give me your
code, and i'll test it....

 
Reply With Quote
 
BBert
Guest
Posts: n/a
 
      27th Jan 2005
On Wed, 26 Jan 2005 18:57:59 GMT, Centurion wrote...

> 1) how do I test (within VBA) to see if the file exists.


Sub FileExists()
Dim fFileExists As Boolean

fFileExists = (Len(Dir("C:\config.sys")) > 0)
If fFileExists = True Then
msgbox "File Exists"
Else
msgbox "No File Found"
End If
End Sub

--
Met vriendelijke groeten / Mit freundlichen Grüßen / With kind
regards/Avec mes meilleures salutations
BBert

April 20, 1986
Celtics (135) - Bulls (131)
Larry Bird: "God disguised as Michael Jordan"
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with an error checking routine JRough Microsoft Access 4 12th Jun 2009 09:10 PM
Call to Sub Routine which exists in seperate workbook Coby Microsoft Excel Programming 4 26th Jan 2008 12:32 AM
VBA routine in detail on print routine causing errors in report Jeff Wimer Microsoft Access Reports 0 21st Oct 2005 01:54 AM
Automating a data checking routine Tony Microsoft Excel Programming 0 12th Nov 2004 11:03 AM
My audit routine routine fails. Run-time error '3622' "You must use the dbSeeChanges..." Adam Microsoft Access Form Coding 1 23rd Oct 2003 12:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:49 AM.