Solved

Is File Open From Vb5 APP

Posted on 1998-07-13
5
170 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

831 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