Solved

Is File Open From Vb5 APP

Posted on 1998-07-13
5
168 Views
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?
0
Comment
Question by:gali040898
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

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

Author Comment

by:gali040898
ID: 1465672
i have to delete the file!!!
0
 
LVL 9

Accepted Solution

by:
Dalin earned 20 total points
ID: 1465673
gali,
Try this, see if it works for you.
Regards
Dalin

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

fFileExistErrorHandler:
   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
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1465674
Gali,
You should pass the fileName with full path.

Function KillFile (theFile as String) as Boolean
.
0
 

Author Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now