Automatic shutdown issues with saving if someone's in the workbook and it's read-only

  • Hi
    I use the following code to automatically close the workbook after a period of inactivity. It's very much based on the work of others, but I think an improvement, because it works flawlessly (with caveat below) and is simple to implement.
    The problem is if someone else was IN the workbook when the user opened it, the code still tries to save it when they exit, causing all sorts of problems because it can't, so it just plonks a copy of the workbook somewhere in the network share. And it shows an ugly error to the user.
    User Module


    ThisWorkbook


    I tried to add IF statements using the boolean variable OPENORNOT to only "Thisworkbook.save" if the answer was FALSE, but that didn't work at all. Any tips? Anyone care to try this out a bit?


    THANKS!!

  • Re: Automatic shutdown issues with saving if someone's in the workbook and it's read-


    Try the following in place of ThisWorkbook.Save


    Code
    If ThisWorkbook.ReadOnly Then
        ThisWorkbook.Saved = True
    Else
        ThisWorkbook.Save
    End If
  • Re: Automatic shutdown issues with saving if someone's in the workbook and it's read-


    oo that sounds fruity, thanks! I'll try it

  • Re: Automatic shutdown issues with saving if someone's in the workbook and it's read-


    Quote from jbell;597144

    Try the following in place of ThisWorkbook.Save


    Code
    If ThisWorkbook.ReadOnly Then
        ThisWorkbook.Saved = True
    Else
        ThisWorkbook.Save
    End If



    Sounded amazing, but doesn't work. The user is now prompted to save when exiting.


    Any other ideas? :)

  • Re: Automatic shutdown issues with saving if someone's in the workbook and it's read-


    Quote from boombox;597496

    Sounded amazing, but doesn't work. The user is now prompted to save when exiting.


    Any other ideas? :)


    If a user opens the workbook when another user already has it open, are they getting prompted to open as 'Read Only'. It sounds like that might not be happening.


    You could try picking up any errors when saving and handling them in code rather than getting the ugly VBA default errors. (Code Below)


    User Module


    ThisWorkbook

  • Re: Automatic shutdown issues with saving if someone's in the workbook and it's read-


    Quote from jbell;597501

    If a user opens the workbook when another user already has it open, are they getting prompted to open as 'Read Only'. It sounds like that might not be happening.
    You could try picking up any errors when saving and handling them in code rather than getting the ugly VBA default errors. (Code Below)


    This works beautifully, I think. Thank you!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!