Is File Open From Vb5 APP

Posted on 1998-07-13
Medium Priority
Last Modified: 2010-05-03
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?
Question by:gali040898
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Expert Comment

ID: 1465671
Switch off error trapping, try to delete it, then see if it still there (you could event check the last error code)!

Author Comment

ID: 1465672
i have to delete the file!!!

Accepted Solution

Dalin earned 80 total points
ID: 1465673
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

Expert Comment

ID: 1465674
You should pass the fileName with full path.

Function KillFile (theFile as String) as Boolean

Author Comment

ID: 1465675
Dalin Thanks!
I just Used The kill File_name with the error handler.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question