Thread: bad file name
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default bad file name

Dim sStr as String
sStr = ""
On error resume next
sStr = Dir(sName)
On Error goto 0
if sStr < "" then


--
Regards,
Tom Ogilvy

"Mike Archer" wrote in message
...
Hello all
The following line returns a run time error 52 (bad file
name) occasionally when sName does not exist:

If Dir(sName) < "" Then

The If block code should be skipped when sName does not
exist, not return an error. The error occurs
sporadically. Most of the time, the code performs as
expected. When the error occurs, it will not repeat in
debug mode (it steps through the line just fine).

Am I doing something wrong with the Dir statement or is
there a more stable way to check for the existence of
sName without creating a lot of overhead?
TIA
Mike