+ Reply to Thread
Results 1 to 5 of 5

Checking to see if a file has been opened in Read/Write or Read Only

  1. #1
    Valued Forum Contributor
    Join Date
    10-13-2010
    Location
    Sunderland, England
    MS-Off Ver
    Excel 2007 (Home) / 2003 (Work)
    Posts
    740

    Checking to see if a file has been opened in Read/Write or Read Only

    Hi guys

    I feel like this should be simple but I don't seem to be able to work out the answer.

    Currently I have a sheet containing data that is used by around 50 users. They each have their own allocator sheet, which (when a macro runs) then opens up the master sheet, takes some data, then saves and closes the master sheet again. This way there are no sharing violations, etc, and each item is only allocated to one person.

    In order for this to work, the allocator sheet checks to see if the master sheet is in use before opening it, using the following:

    Please Login or Register  to view this content.
    and then in the main code:

    Please Login or Register  to view this content.
    This works fine 99% of the time, but there have been a small number of incidents where people have both downloaded the same items. I believe this is because the file takes a small amount of time to open, and isn't opened until after the check is done. So if 2 people run the macro almost simultaneously, the second person's sees that the file isn't in use, and starts to open it - but the first person's has already opened the file by this stage.

    So what I'd like to do is check (once the file has been opened for use) to see if the file is only opened as 'read-only' state, and if so to repeat the process again.

    Any ideas guys?
    Last edited by brokenbiscuits; 01-13-2014 at 09:17 AM.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Checking to see if a file has been opened in Read/Write or Read Only

    Try:

    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Valued Forum Contributor
    Join Date
    10-13-2010
    Location
    Sunderland, England
    MS-Off Ver
    Excel 2007 (Home) / 2003 (Work)
    Posts
    740

    Re: Checking to see if a file has been opened in Read/Write or Read Only

    Thanks for the suggestion - for some reason I had it in my head that the ReadOnly attribute would only work if the file's properties were set to read only. It didn't like the With statement for some reason (Runtime Error 9), but a slight amendment is working great!

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Checking to see if a file has been opened in Read/Write or Read Only

    Ah, I forgot the End With, that's all

    Glad it helped anyway.

  5. #5
    Valued Forum Contributor
    Join Date
    10-13-2010
    Location
    Sunderland, England
    MS-Off Ver
    Excel 2007 (Home) / 2003 (Work)
    Posts
    740

    Re: Checking to see if a file has been opened in Read/Write or Read Only

    No, I stuck and End With on, but still no dice. It doesn't seem to like the strFileName, even though it uses it above. But no problem anyway, works fine for me!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 06-26-2012, 02:00 PM
  2. Skip The Read Only Prompt When I Open A File - Excel, Open it read-write instead.
    By harry_1805 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2012, 02:14 AM
  3. stop excel file opened as read only if already opened by another u
    By bobm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-09-2011, 08:45 AM
  4. [SOLVED] I have a read only xl file, I need it to be read and write
    By drama queen in forum Excel General
    Replies: 3
    Last Post: 06-30-2006, 07:30 PM
  5. How can a file be converted from Read-Only to Read/Write
    By Jim in Apopka in forum Excel General
    Replies: 2
    Last Post: 11-19-2005, 01:00 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1