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?
LMG09Asked:
Who is Participating?
 
Ajay ChananaMCSE-2003/08|RHCSA| VCP5/6 |vExpert2018Commented:
I don't think that would be possible , as in both the ways it's authentic user. I tried to find if we can open only single instance unfortunately that's not possible.
0
 
Ajay ChananaMCSE-2003/08|RHCSA| VCP5/6 |vExpert2018Commented:
You can use sharepoint as solution to it where multi user access  the file.

Other way you can check below  link.

https://www.youtube.com/watch?v=yzcyEKgj9hg
0
 
LMG09Author Commented:
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?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Roy CoxGroup Finance ManagerCommented:
This code will close an inactive workbook


''// In the Workbook module

Private Sub Workbook_Open()
    EndTime = Now + TimeValue("00:10:00")
    RunTime
End Sub

Open in new window

This resets the timer if a change in the workbook occurs

Worksheet 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

Open in new window


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

Open in new window

0
 
Roy CoxGroup Finance ManagerCommented:
If you need to check for changes in all sheets of the workbook then use the Workbook_SheetChange event
0
 
LMG09Author Commented:
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
0
 
LMG09Author Commented:
Ajay - I agree with your comments but I thought I would put it out to the experts - just in case it was possible
0
 
Roy CoxGroup Finance ManagerCommented:
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.
0
 
LMG09Author Commented:
Thanks for all of your input
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.