Solved

Is File Open From Vb5 APP

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

911 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

19 Experts available now in Live!

Get 1:1 Help Now