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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.