How to create routine success = OpenFile

  • Thread starter Thread starter hansmbg
  • Start date Start date
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
 
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.
 
Back
Top