Is File Open From Vb5 APP

How do i know if for example Excel file is open from Vb5 Application, befor i am trying to delete  this file so i will not get an error while trying to delete an open file.
Is there any function in vb5 or dll function in winodws api?
Who is Participating?
DalinConnect With a Mentor Commented:
Try this, see if it works for you.

Function KillFile
Dim lifh As Integer ' file handle variable

On Error GoTo fFileExistErrorHandler '    enable our error handler
   lifh = FreeFile ' get the next available free file handle
   Open TheFile For Input As lifh ' try and open it for reading
   Close lifh ' be sure to close it
   Kill theFile
   Exit Function

   Select Case Err
          Case 52  'bad file name or number
            Exit Function
          Case 53  'file not found
            Exit Function
          Case 55  'file already open
            'File is Open Somewhere
            Exit Function

          Case 75  'path/file access error
            Exit Function
          Case 76  'path not found
            Exit Function
          Case Else ' something else happened - so just report it
            Exit Function
   End Select

End Function
Switch off error trapping, try to delete it, then see if it still there (you could event check the last error code)!
gali040898Author Commented:
i have to delete the file!!!
You should pass the fileName with full path.

Function KillFile (theFile as String) as Boolean
gali040898Author Commented:
Dalin Thanks!
I just Used The kill File_name with the error handler.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.