Results 1 to 4 of 4
  1. #1
    3 Star Lounger siflaar's Avatar
    Join Date
    Jan 2001
    Location
    Amersfoort, Netherlands
    Posts
    203
    Thanks
    4
    Thanked 0 Times in 0 Posts

    ReadOnly:=False is false (NL/2003)

    Hello All,

    In my code I use the following line:
    Workbooks.Open Filename:=strFileName, ReadOnly:=False, UpdateLinks:=False
    And allthough I say ReadOnly:=False, if the workbook is already open by another user it is opened as ReadOnly.
    Is there a way to check if the book is opened with the ReadOnly status to True, because then I can show a message that the update will not work and close the workbook

    Thanks inadvance for your reactions.
    Greetings,

    Patrick Schouten
    (The Netherlands)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: ReadOnly:=False is false (NL/2003)

    You can use this function to test:

    Function IsFileOpen(FileName As String) As Boolean
    Dim f As Integer
    Dim intErr As Integer

    On Error Resume Next ' Turn error checking off.
    f = FreeFile
    ' Attempt to open the file and lock it.
    Open FileName For Input Lock Read As #f
    intErr = Err ' Save the error number that occurred.
    Close f ' Close the file.

    ' Check to see which error occurred.
    Select Case intErr
    Case 0
    ' No error occurred.
    ' File is NOT already open by another user.
    Case 70
    ' Error number for "Permission Denied."
    ' File is already opened by another user.
    IsFileOpen = True
    Case Else
    ' Another error occurred.
    Error intErr
    End Select
    End Function

    Example of use:

    If IsFileOpen(strFileName) Then
    MsgBox "Workbook is already in use.", vbExclamation
    Else
    Workbooks.Open
    End If

    By the way, were the replies to <post:=723,237>post 723,237</post:> and <post:=724,311>post 724,311</post:> useful? You didn't provide any feedback.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ReadOnly:=False is false (NL/2003)

    You can test for the readonly mode:

    If Workbooks("Foo.xls").ReadOnly Then
    'Book is in readonly mode
    End If
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  4. #4
    3 Star Lounger siflaar's Avatar
    Join Date
    Jan 2001
    Location
    Amersfoort, Netherlands
    Posts
    203
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: ReadOnly:=False is false (NL/2003)

    Hans and Jan Karel,
    I'm sure that the solution of Hans will work, but i'm using the short version of Jan Karel.
    It works perfect.
    Thanks.
    Greetings,

    Patrick Schouten
    (The Netherlands)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •