How to create routine success = OpenFile

H

hansmbg

Newbie question.
I want a routine that checks if a file exists and returns
a value 0 for FALSE and 1 for TRUE.
I have been looking around, but I can not find any routine
that RETURNS a value after attempting to open a file.
Thank you in advance

idea:

Sub OpenTest
flag = openfile
if flag = 0 exit all macros
EndSub

/Hans
 
J

JE McGimpsey

one way:

Public Function FileExists(sFileName As String, _
Optional sPath As String) As Boolean
If sPath = "" Then sPath = CurDir()
FileExists = Dir(sPath & Application.PathSeparator & _
sFileName) <> ""
End Function

Which returns True or False, which is what your sub seems to require
rather than coercing to 1/0:

If Not FileExists(<filename>) Then End

Note that this doesn't attempt to open the file - it just checks for
existence.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top