• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

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?
0
gali040898
Asked:
gali040898
  • 2
  • 2
1 Solution
 
chris_aCommented:
Switch off error trapping, try to delete it, then see if it still there (you could event check the last error code)!
0
 
gali040898Author Commented:
i have to delete the file!!!
0
 
DalinCommented:
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
 
DalinCommented:
Gali,
You should pass the fileName with full path.

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now