Detecting if a user has a file open
Detecting if a user has a file open
Detecting if a user has a file open
Detecting if a user has a file open
Detecting if a user has a file open
Detecting if a user has a file open Detecting if a user has a file open Detecting if a user has a file open Detecting if a user has a file open Detecting if a user has a file open Detecting if a user has a file open Detecting if a user has a file open Detecting if a user has a file open
Detecting if a user has a file open Detecting if a user has a file open
Detecting if a user has a file open
Go Back  Xtreme Visual Basic Talk > > > Detecting if a user has a file open


Reply
 
Thread Tools Display Modes
  #1  
Old 10-24-2016, 06:12 AM
Daigon Ali Daigon Ali is offline
Regular
 
Join Date: Aug 2014
Location: London
Posts: 59
Default Detecting if a user has a file open


Hi,

Is there any way in VB6 to detect if a user has an Excel file open on their machine?

The Excel file is always opened as Read Only so the file's availability is always "available".

I just need to know if they have it open.
Reply With Quote
  #2  
Old 10-24-2016, 04:41 PM
Cerian Knight's Avatar
Cerian KnightDetecting if a user has a file open Cerian Knight is online now
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,194
Default

If your VB6 application did not automate the open, then you could trap for an error on opening the file yourself:
Code:
'For VB6; similar to, and interchangeable with, a Microsoft VBA code example
Dim FileNum as Long
FileNum = FreeFile
On Error Resume Next
Open "your drive/path/ExcelFilenameHere" For Input Lock Read As #FileNum
Close FileNum
If Err <> 0 Then
    Debug.Print "File is already open"
Else
    Debug.Print "File is not already open"
End If
On Error Goto 0
Oddly, this code was not working for me initially because I had 'Break on All Errors' set in my VB Options... I hate errors, so try to avoid writing code that requires 'On Error...", when possible, so I don't accidentally mask one I need to know about during development. To that end... there are other more complicated methods of doing this (by creative use of CreateFile API).
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #3  
Old 10-25-2016, 10:33 AM
Daigon Ali Daigon Ali is offline
Regular
 
Join Date: Aug 2014
Location: London
Posts: 59
Default

Hi Cerian,

Many thanks for your reply. The file I'm opening is an Excel workbook which has its Read Only property set to True, so anyone opening it only opens a Read Only copy.

Because the user has open a Read Only copy, your code does not generate the error. However they still have the file open on their machine.

As the file name of this Excel file remains constant, I thought there might be some way of checking the window captions or Task Manager names?
Reply With Quote
  #4  
Old 10-27-2016, 03:52 AM
Daigon Ali Daigon Ali is offline
Regular
 
Join Date: Aug 2014
Location: London
Posts: 59
Default

Reply With Quote
Reply

Tags
availability, excel, file, files, user, detecting


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Detecting if a user has a file open
Detecting if a user has a file open
Detecting if a user has a file open Detecting if a user has a file open
Detecting if a user has a file open
Detecting if a user has a file open
Detecting if a user has a file open Detecting if a user has a file open Detecting if a user has a file open Detecting if a user has a file open Detecting if a user has a file open Detecting if a user has a file open Detecting if a user has a file open
Detecting if a user has a file open
Detecting if a user has a file open
 
Detecting if a user has a file open
Detecting if a user has a file open
 
-->