Requirement:
The user would like to open an excel workbook in read only if the computer user and computer name doesn’t match existing criteria.
Example: if the main person to open the workbook is computer name is WS2019, and the logon name is wsmith, but the computer name opening the wb is RS2019 and the login name is rgraves, then the user needs the excel workbook to open up in “read only” so the the excel workbook cannot be saved and if changes need to be made, only wsmith can open it and make the changes. The user has multi-users that use this excel workbook everyday and if changes need made, only the user knows how to make them. The user is not always the first to open it up and so if changes needs made, everyone needs to close the workbook so that it can open it and make the changes. The user also doesn't want the possibility that the workbook can be saved.
Solution:
Private Sub Workbook_Open() On Error Resume Next If Environ("USERNAME") <> " enter name here" Then ThisWorkbook.ChangeFileAccess Mode:=xlReadOnly End Sub
Obtained from the OzGrid Help Forum.
Solution provided by royUK.
See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets
See also:
How to use VBA code to output multiple worksheets to separate workbooks |
How to search for a word inside a workbook and open that sheet as active sheet |
How to compare two workbooks with multiple sheets and highlighting duplicates |
How to use a macro to copy data from multiple workbooks to one master sheet in another workbook |
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.