open the file read only all the time

baha17

Board Regular
Joined
May 12, 2010
Messages
181
Hi All,
I have a workbook which triggers vba code and records all data in access database. Now what I want is to open the file as read only when the username is:"pit".I do not have a hope for that but any chance that some one has a trick for that.For some reason I do not want to share workbook.

Thank you in advance for your help

Baha
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Is this just for one user, or do you want it opened read-only for everyone but e.g. people knowing a password? If the latter, Select File, save-as, click the Tools dropdown and select "General Options"and set a password for modification.
 
Upvote 0
Hi jkpierterse,

Thank you verymuch for your input.Is there any other way rather than password protection?It can be read only for one user or read only all user except one user.
Thank you for your help

Baha
 
Upvote 0
In Thisworkbook module, WOrkbook_Open event:

Code:
Private Sub Workbook_Open()
    If Environ("username") = "pit" Then
        Application.DisplayAlerts = False
        ThisWorkbook.ChangeFileAccess xlReadOnly
    End If
End Sub
 
Upvote 0
Hi Jan,

Thank you very much for the help.I can only test that tomorrow. But just wanna ask, does that mean with that code, more than one user can open the file without displaying any message and file would be read only. If like that "pit" users cannot save the file right?
Baha
 
Upvote 0
All users will open the file with read-write access, Except "pit".
However, if the file is already opened by someone else than pit, the other users will open the WB read-only of course.
 
Upvote 0

Forum statistics

Threads
1,215,566
Messages
6,125,589
Members
449,237
Latest member
Chase S

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top