LMG09
asked on
How to lock an open excel spreadsheet
Hi - We have an excel spreadsheet located within a shared folder on a Windows server. 3 users will access and update this spreadsheet at various times throughout the day. When one user is accessing the spreadsheet, we would like any other users who try to access the spreadsheet to be told that it's in use and to try again later. We do not want the spreadsheet to be opened in read only mode. Is this possible?
ASKER
Ajay - Thanks for your prompt response.
Unfortunately, we do not want multiple users to access the spreadsheet at the same time. When one user accesses the spreadsheet, we need to prevent other users from accessing it at the same time (not even read only mode). Is this possible?
Unfortunately, we do not want multiple users to access the spreadsheet at the same time. When one user accesses the spreadsheet, we need to prevent other users from accessing it at the same time (not even read only mode). Is this possible?
This code will close an inactive workbook
Worksheet Change Event
If no changes have occurred then this runs
in a Standard Module
''// In the Workbook module
Private Sub Workbook_Open()
EndTime = Now + TimeValue("00:10:00")
RunTime
End Sub
This resets the timer if a change in the workbook occursWorksheet Change Event
Private Sub Worksheet_Change(ByVal Target As Range)
If EndTime Then
Application.OnTime _
EarliestTime:=EndTime, _
Procedure:="CloseWB", _
Schedule:=False
EndTime = Empty
End If
EndTime = Now + TimeValue("00:10:00")
RunTime
End Sub
If no changes have occurred then this runs
in a Standard Module
Public EndTime
Sub RunTime()
Application.OnTime _
EarliestTime:=EndTime, _
Procedure:="CloseWB", _
Schedule:=True
End Sub
Sub CloseWB()
Application.DisplayAlerts = False
With ThisWorkbook
.Saved = True
.Close
End With
End Sub
If you need to check for changes in all sheets of the workbook then use the Workbook_SheetChange event
ASKER
Thanks Roy for your prompt response. Unfortunately, It doesn't seem to answer my question (unless I'm totally missing the point :-))
If you had a spread sheet open and I tried to open that spread sheet as well, by default I would be able to open that spreadsheet in read only mode. I need a way of denying me access to the spreadsheet altogether whilst you still have that spread sheet open. When you close the spreadsheet, I'm then able to access the spreadsheet as normal. I hope this makes sense?
Regards
If you had a spread sheet open and I tried to open that spread sheet as well, by default I would be able to open that spreadsheet in read only mode. I need a way of denying me access to the spreadsheet altogether whilst you still have that spread sheet open. When you close the spreadsheet, I'm then able to access the spreadsheet as normal. I hope this makes sense?
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ajay - I agree with your comments but I thought I would put it out to the experts - just in case it was possible
I have code that would detect if the workbook is open that works if the users are opening the file by means of VBA. It doesn't seem to work when opening from Windows Explorer, but I've not tested using a shared folder. I can post the code if you want to try it.
The code I posted earlier was intended to close the workbook if it remained idle, reducing the need for other users to wait unnecessarily.
The code I posted earlier was intended to close the workbook if it remained idle, reducing the need for other users to wait unnecessarily.
ASKER
Thanks for all of your input
Other way you can check below link.
https://www.youtube.com/watch?v=yzcyEKgj9hg