The file is locked. Try the command again later on

    • #1

    Hello all,

    I've been getting this error on occasion recently.

    - It's a shared document
    - In that location is usually 10-12 people using the file at the same time

    I've read on the Microsoft Assist site that the event is that somebody is accessing the file while some other is trying to open up it.

    Is there a mode, perhaps through VBA, that I can not let a user to save while somebody else is opening the certificate? Other suggestions on how to avoid this mistake?

    Thanks!

    • #ii

    Re: The file is locked. Try the command over again later

    Y'all could add this part in a VBE module

    Then something like this in the workbook module

                                                                                        Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel Every bit Boolean)                                                                                                                    Dim fName Every bit String                                                                                                                    fName = "your file name" 'file proper name goes here                                                                                                                    If IsFileLocked(fName) And then                                                                                                                                                    MsgBox ("File is locked" & vbCrLf & "Please try again later")                                                                                                                                                    Abolish = Truthful                                                                                                                    End If                                                                                                                    Terminate Sub                                                                              
    • #3

    Re: The file is locked. Effort the control again later

    Hi EggCell,

    First, sorry information technology took and then long to get back - busy! The formula looks good - the only trouble is where I need to insert the filename:

                                                                                        fName = "your file name" 'file name goes here                                                                              

    The filename changes daily. How would I insert a variable there that would reflect the electric current filename?

    Thanks once more for your assist,

    Eric

    • #iv

    Re: The file is locked. Try the command again later

    Hi EggCell,

    I've placed the code in the ThisWorkbook module, and identified the filename as below:

                                                                                        Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel Every bit Boolean)                                                                                                                    Dim fName As Cord                                                                                                                    fName = ThisWorkbook.Name                                                                                                                    If IsFileLocked(fName) Then                                                                                                                    MsgBox ("File is locked" & vbCrLf & "Delight effort again afterward")                                                                                                                    Cancel = Truthful                                                                                                                    Cease If                                                                                                                    End Sub                                                                              

    Now - the condition bar continually says "Waiting for file to close" and I get the "The file is locked. Delight endeavour once more later" bulletin each time I endeavour to save the file, despite the file not being shared.

    • #5

    Re: The file is locked. Attempt the command once more later

    Quote

    Now - the status bar continually says "Waiting for file to close" and I get the "The file is locked. Please endeavor once more later" bulletin each fourth dimension I endeavor to save the file, despite the file not existence shared.

    one. Delete the lines with Application.StatusBar alltogether, they're non and then useful.
    2. "The file is locked. Delight try once again subsequently" Isn't that normal if y'all test ThisWorkbook (yous use ThiosWorkbook.Proper noun and run into if it's open or not -obviously it'south open).

    • #vi

    Re: The file is locked. Try the control again later

    Howdy Wigi,

    I thought the code there checks, not if the file is open up, merely if the file is locked (while somebody else is saving it, for example...)

                                                                                        fName = ThisWorkbook.Proper noun                                                                                                                                                    If IsFileLocked(fName) Then                                                                              

    If this is not the case, is there another mode to word it ?

    • #vii

    Re: The file is locked. Try the command again afterward

    Would it exist helpful if you test the number of users in the file?

                                                                                        MsgBox UBound(ActiveWorkbook.UserStatus)                                                                              
    • #8

    Re: The file is locked. Try the control once more afterwards

    Hmm... I'm not sure if that would assistance - the goal is to forbid somebody trying to admission/open the file while it is existence saved to by somebody else. Co-ordinate to the MS KB article, the mistake bulletin "The file is locked. Try the command again later" is considering I am trying to open the shared while at the aforementioned fourth dimension, another user has clicked Salvage. The problem is, that once a user gets this message, trying Salve over again in a few minutes does not issue in Saving to the original file, it forces a Save As and salve a second copy of the file.

    • #nine

    Re: The file is locked. Try the command again later

    I actually haven't worked with shared workbooks too much, and I wasn't certain how the fileislocked part would piece of work in that instance. To Wigi'southward point, it apparently shows that it's locked because you accept it open. Try this code and see if it doesn't practise what you need. It saves as a "temp" file and and then checks to meet if the original file is open. The Practice...Loop will wait until the file is not locked (presumably subsequently no user is opening information technology) and and then will save information technology and delete the copy.

    • #10

    Re: The file is locked. Endeavor the control again later

    And so I got a "Sub of Function non defined" for "IsFileLocked"

                                                                                        Do Until Non IsFileLocked(fName)                                                                              

    Strange, because I didn't get that for the aforementioned statement before ...

    • #xi

    Re: The file is locked. Effort the command once again subsequently

    Quote from nameltrab;579198

    So I got a "Sub of Function not divers" for "IsFileLocked"

                                                                                                    Practice Until Not IsFileLocked(fName)                                                                                          

    Foreign, because I didn't get that for the same statement earlier ...

    I don't go that bulletin. Do you lot have the office inside the aforementioned workbook?

    • #12

    Re: The file is locked. Attempt the command again later

    oops - pocket-sized error on my role! It seems to be working ! Hard to know for certain until I get everybody using it ... Thanks for your help guys! I'll let you know how it goes!

    Thank you once more for your time,

    Eric

    • #13

    Re: The file is locked. Try the control again subsequently

    Alter the file name. or Copy the file in your desktop --> rename information technology --> supplant the shared file with this new renamed one This worked for me. this is more than a network issue or combination of network or file

  • Newly created posts will remain inaccessible for others until approved past a moderator.

    The last reply was more than 180 days ago, this thread is almost likely obsolete. Information technology is recommended to create a new thread instead.