File Open - force Read Only for specified users

Gerald Higgins

Well-known Member
Joined
Mar 26, 2007
Messages
9,258
Hi all, did a search, found this
http://www.mrexcel.com/forum/showthread.php?t=370089&highlight=force+read
which got me half way there, but looking for help on the last bit.

I've got a file which I would like to set up so that certain specified users can only open it as read only, while other specified users can open a read/write version.

I don't really mind which way round this works - either I would specify the read only users, and all others would be read/write by default, OR I'd be happy to specify the users who could read/write, and all others would be read only by default.

I adapted the code in that other thread to this,
Code:
If Not ActiveWorkbook.ReadOnly Then 
ActiveWorkbook.ChangeFileAccess Mode:=xlReadOnly
which works. I've incorporated it into the Auto Open routine, and it correctly makes the file read only.

What I want to do is add something that says effectively...

If user = John Smith, Jane Brown
open the file as read only
else

and I need help with the bit in bold.

Any ideas ?

Thanks in advance...
 
The code here did not work for me...but I got this to work using Environ username. Take care.

Code:
Private Sub Workbook_Open()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
If Environ("username") <> "[COLOR=#ff0000][B]jswan[/B][/COLOR]" Then
    If Not ActiveWorkbook.ReadOnly Then
    ActiveWorkbook.ChangeFileAccess Mode:=xlReadOnly
    End If
End If
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

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