M
mark kubicki
I want to check if a SHARED workbook is open (on the user's machine), so
that I can run code to open it if it is not (otherwise I would get a message
about opening an already open ... the workbook is HIDDEN to the user, to the
message would be both inappropriate and confusing...)
in the past I've used this procedure, but the workbook was NOT SHARED (since
it is now shared, it would be possible to get an "is open" response even
though it was not so on the user's machine:
Function IsFileOpen(filename As String)
Dim filenum As Integer, errnum As Integer
On Error Resume Next
filenum = FreeFile()
Open filename For Input Lock Read As #filenum
Close filenum
errnum = Err
On Error GoTo 0
Select Case errnum
Case 0
IsFileOpen = False
Case 70
IsFileOpen = True
Case Else
Error errnum
End Select
End Function
it was suggested that I check for the workbooks status, but that doesn't
tell me if it is "open" on the user's machine (only if is shared or
exclusive...)
Dim vMode
On Error Resume Next
If Me.ReadOnly Then
vMode = 3
Else
vMode = Application.VLookup(Application.UserName, Me.UserStatus, 3)
End If
MsgBox "Mode: " & Choose(vMode, "exclusive", "shared", "readonly")
thanks in advance
that I can run code to open it if it is not (otherwise I would get a message
about opening an already open ... the workbook is HIDDEN to the user, to the
message would be both inappropriate and confusing...)
in the past I've used this procedure, but the workbook was NOT SHARED (since
it is now shared, it would be possible to get an "is open" response even
though it was not so on the user's machine:
Function IsFileOpen(filename As String)
Dim filenum As Integer, errnum As Integer
On Error Resume Next
filenum = FreeFile()
Open filename For Input Lock Read As #filenum
Close filenum
errnum = Err
On Error GoTo 0
Select Case errnum
Case 0
IsFileOpen = False
Case 70
IsFileOpen = True
Case Else
Error errnum
End Select
End Function
it was suggested that I check for the workbooks status, but that doesn't
tell me if it is "open" on the user's machine (only if is shared or
exclusive...)
Dim vMode
On Error Resume Next
If Me.ReadOnly Then
vMode = 3
Else
vMode = Application.VLookup(Application.UserName, Me.UserStatus, 3)
End If
MsgBox "Mode: " & Choose(vMode, "exclusive", "shared", "readonly")
thanks in advance