Prevent two network users from opening same workbook?

  • Thread starter Thread starter Ed
  • Start date Start date
E

Ed

If a workbook is already open and a user tries to open it across a
network connection, they get the "Read Only / Notify" dialog. Is
there a convenient way to detect that one user already has the
workbook open, and prevent a second user from opening the file at all,
not even as Read Only?

Ed
 
Here's a way I've been using:
Function IsFileOpen(filename As String)
Dim fnum As Integer
Dim errnum As Integer
On Error Resume next

fnum = FreeFile()

Open filename For Input Lock Read As #fnum
Close fnum
errnum = Err
If Err <> 0 Then
IsFileOpen = True
Else
IsFileOpen = False
End If
On Error GoTo 0
End Function

this function returns true if the file is open somewhere, so you call the function and only continue to open the file if it returns true.
 
There is no "convenient way" to do this. It can be done but is not
convenient as it requres using Windows API calls and a lot of faffing about.
 
Ed,
You can add code to workbook's Open event and see if its .ReadOnly property
is true.
Then put up a msgbox and .Close.

However, if the user disables macros/events, then this will not function.
Or if the user actually wants it open as ReadOnly.

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top