Prevent a user from using a file that is open in Excel

Charliecherche Posted messages 2 Registration date   Status Member Last intervention   -  
 Psy-no-pb -

Hello,

I want to set an Excel file to read-only if another user attempts to modify it when it is already open.


4 answers

  1. danielc0 Posted messages 2199 Registration date   Status Member Last intervention   288
     

    Hello,

    Why not set it to read-only all the time?

    Daniel


    0
  2. danielc0 Posted messages 2199 Registration date   Status Member Last intervention   288
     

    Otherwise, but I don’t see much point, per macro. Put this code in the "ThisWorkbook" module:

    Private Sub Workbook_BeforeClose(Cancel As Boolean) SetAttr "D:\OneDrive\mpfe\lectureseule.xlsm", vbNormal End Sub Private Sub Workbook_Open() SetAttr "D:\OneDrive\mpfe\lectureseule.xlsm", vbReadOnly End Sub 

    By replacing the path and file name (and again, this is to be tested). Then, you will need to modify the file to be (roughly) sure that VBA is enabled. And lock the VBA project. If you want details, ask.

    Daniel

    PS. It doesn’t prevent modifications, it prevents saving them.


    0
  3. Psy-no-pb
     

    Hello,

    ""

    Lock or unlock a workbook to make it read-only

    1. From the File menu, select Always open read-only. ...
    2. To require a password, in the File menu, select Passwords and enter a password to open the file.
    0