Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Opening a network file - testing for ReadOnly

Opening a network file - testing for ReadOnly

Opening a network file - testing for ReadOnly

Hi all

I need my userform to open an additional file for input. The file is on a network drive, so I need to perform the following checks:

1) the current user hasn't already got the file open in the background (this works)
2) another user hasn't got the file open (which would open in readonly)

Here is what I have. I'm getting a Subscript error on the readonly check


Dim wFilePath As String
    Dim wFileName As String
    Dim wWB As Workbook
    wFilePath = "\\MAIN-PC\Users\Public\"
    wFileName = "TESTFILE.xlsx"

'check if this user has the workbook open already
    If FileInUse(wFilePath & wFileName) Then
        Set wWB = Workbooks("TESTFILE.xlsx")
        Set wWB = Workbooks.Open(wFilePath & wFileName)
    End If
    If wWB.ReadOnly = True Then
        MsgBox "file is readonly"
        wWB.Close False
    End If

Public Function FileInUse(sFileName) As Boolean
    On Error Resume Next
    Open sFileName For Binary Access Read Write Lock Read Write As #1
    Close #1
    If Err.Number <> 0 Then
        FileInUse = True
    End If
End Function 

RE: Opening a network file - testing for ReadOnly

Looks like to check tee ReadOnly you either have to do this:

If wWB(1).ReadOnly = True Then
(if you know the index of your workbook)

or - info from here -

If ActiveWorkbook.ReadOnly Then

Have fun.

---- Andy

There is a great need for a sarcasm font.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close