Is That File Open?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

thought I had seen the answer out here some where, but can't find it.
I am having trouble with a module that reads data from an Excel spreadsheet
sometimes. I think it may have to do with the fact that another user may
have it open.
I know how to tell if an App is open on my machince, but what I can't find
is how to determine if another user has a spreadsheet on a shared network
folder open.
(Your kind assistance will be appreciated and plagerized)
 
One approach is to try and do something that requires exclusive access
to the file and see if it fails, e.g. (air code)

Dim lngFN as Long
On Error Resume Next
Open strFileSpec For Binary Access Read Lock Read Write As #lngFN
If Err.Number <> 0 Then
'Something else has the file open
Err.Clear
Else
'We have the file, therefore no one else does
Close #lngFN
End If
On Error Goto 0
 
Thanks, John.

John Nurick said:
One approach is to try and do something that requires exclusive access
to the file and see if it fails, e.g. (air code)

Dim lngFN as Long
On Error Resume Next
Open strFileSpec For Binary Access Read Lock Read Write As #lngFN
If Err.Number <> 0 Then
'Something else has the file open
Err.Clear
Else
'We have the file, therefore no one else does
Close #lngFN
End If
On Error Goto 0
 
Thanks again, John. I do plan to try this out. I had thought I was having a
problem opening and using an Excel sheet that someone else had open. I kept
getting intermittent errors. A line of code would work sometimes and not
others. It turned out to be the old object referencing problems. I somehow
had established an extra instance of Excel I was unaware of and I think it
was getting confused on which instance it was talking to.
 
Back
Top