Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
pete
 
Posts: n/a
Default Micro that checks if file exists

Hi, everyone.
I have a micro that opens other files to copy data to this file. How can I
make it to skip a file that does not exist and continue to the next one?

Thanks for your help.
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default


Set thisFile = Workbooks.Open("filename")
If Not thisFile Is Nothing Then
'your code
Else
'get the next
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"pete" wrote in message
...
Hi, everyone.
I have a micro that opens other files to copy data to this file. How can

I
make it to skip a file that does not exist and continue to the next one?

Thanks for your help.



  #3   Report Post  
pete
 
Posts: n/a
Default

Bob,

Thanks for your clue. I still have a problem; if the file does not exist, I
have the "run-time error 1004" which terminates the macro because it will not
allow me to continue.

Anything else I need to add so I if it cannot find the file, it will go to
the next one?

Thanks,
Pete
  #4   Report Post  
Bob Phillips
 
Posts: n/a
Default

Sorry, it shoule be error wrapped

On Error Resume Next
Set thisFile = Workbooks.Open("filename")
On Error Goto 0
If Not thisFile Is Nothing Then
'your code
Else
'get the next
End If


--

HTH

RP
(remove nothere from the email address if mailing direct)


"pete" wrote in message
...
Bob,

Thanks for your clue. I still have a problem; if the file does not exist,

I
have the "run-time error 1004" which terminates the macro because it will

not
allow me to continue.

Anything else I need to add so I if it cannot find the file, it will go to
the next one?

Thanks,
Pete



  #5   Report Post  
pete
 
Posts: n/a
Default

Thanks again, Bob, for your timely fix. I almost got it, except the "Go to 0".
What can I substitute for "0"?


  #6   Report Post  
Myrna Larson
 
Posts: n/a
Default

If you are talking about On Error Goto 0, that statement turns error trapping
off. If you mean a standard Goto statement (yes, it's still around), you have
to set up line numbers/labels and use those in your Goto statements.

On Wed, 23 Mar 2005 13:37:02 -0800, "pete"
wrote:

Thanks again, Bob, for your timely fix. I almost got it, except the "Go to

0".
What can I substitute for "0"?


  #7   Report Post  
pete
 
Posts: n/a
Default

Got it...
Working perfectly.

Million thanks to Bob and Myrna.


  #8   Report Post  
veljo
 
Posts: n/a
Default

Hi Pete,
Could you make public all the code. Seems it is what I am looking for for a
long time.
Thanks,
veljo


"pete" kirjutas:

Got it...
Working perfectly.

Million thanks to Bob and Myrna.


  #9   Report Post  
pete
 
Posts: n/a
Default

Hi Veljo,

I used Bob's suggestion,
1.
On Errror Resume Next
Set nextFile = Workbooks.Open("filename")
On error Goto 0

This portion will get rid of the irritation "run-time error".

2.
If Not nextFile Is Nothing Then
...... begin your code
Else
End If






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening a file with code without a set file name jenkinspat Excel Discussion (Misc queries) 1 March 3rd 05 03:40 PM
Locating a file in excel with a partial file name. Audra Excel Discussion (Misc queries) 1 February 19th 05 08:51 PM
Locating a file in excel with a partial file name. Audra Excel Discussion (Misc queries) 0 February 19th 05 02:03 PM
Locating a file in excel with a partial file name. Audra Excel Discussion (Misc queries) 0 February 19th 05 02:03 PM
Read Text File into Excel Using VBA Willie T Excel Discussion (Misc queries) 13 January 8th 05 12:37 AM


All times are GMT +1. The time now is 07:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"