SnareDrummer
New Member
- Joined
- Jun 26, 2020
- Messages
- 4
- Office Version
- 365
- 2019
- Platform
- Windows
Hello!
Each member of my team has its own Excel file which uploads data into global file. Works fine until two (or more) members try to upload data at the same time. I've tried to make a 'wait and check again' loop based on checking if the global file is locked or not but it doesn't work as expected
My first try was code that I googled (can't find the sourse, sorry):
The function should return an error when trying to open the file for 'read write' type of access as the file is locked and therefor 'read only'. The problem is that the function never returns any error.
I have also tried to search the folder with the global file for temporary file with name starting with '~$' but I get 'file doesn't exist' message.
I have tried the second solution from this site:
Find out who has Excel file locked for editing - wellsr.com
but does not work either.
In addition, when the file is locked I would expect the pop up window with question what to do next: open as read only, notify the user etc. - hope you know what I'm talking about. But instead I a pop up with a message that the file is protected and a text box to type the password into. I really don't get it as the password is provided by the VBA code and works fine when the global file isn't locked.
Any idea how to make this 'wait and check again' loop? Or how to deal with this 'uploading at the same time' problem other way?
Each member of my team has its own Excel file which uploads data into global file. Works fine until two (or more) members try to upload data at the same time. I've tried to make a 'wait and check again' loop based on checking if the global file is locked or not but it doesn't work as expected
My first try was code that I googled (can't find the sourse, sorry):
VBA Code:
Function FileLocked(strFileName As String) As Boolean
On Error Resume Next
' If the file is already opened by another process,
' and the specified type of access is not allowed,
' the Open operation fails and an error occurs.
Open strFileName For Binary Access Read Write Lock Read Write As #1
Close #1
' If an error occurs, the document is currently open.
If Err.Number <> 0 Then
' Display the error number and description.
MsgBox "Error #" & Str(Err.Number) & " - " & Err.Description
FileLocked = True
Err.Clear
End If
End Function
I have also tried to search the folder with the global file for temporary file with name starting with '~$' but I get 'file doesn't exist' message.
I have tried the second solution from this site:
Find out who has Excel file locked for editing - wellsr.com
but does not work either.
In addition, when the file is locked I would expect the pop up window with question what to do next: open as read only, notify the user etc. - hope you know what I'm talking about. But instead I a pop up with a message that the file is protected and a text box to type the password into. I really don't get it as the password is provided by the VBA code and works fine when the global file isn't locked.
Any idea how to make this 'wait and check again' loop? Or how to deal with this 'uploading at the same time' problem other way?