Restrict Excel Access

AndrewD04

New Member
Joined
Aug 24, 2017
Messages
40
Office Version
  1. 365
Hi,

I have a Workbook that i would like to restrict access apart from certain users.

I don't want it to ask for the username and password i would like to it auto detect the username of the person and if they are on the list allow access and if not it wont allow them in the document can anyone help please.

Thanks in advance

Dan
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hey Andrew,

You can use the below code, however if the user haven't enabled macros the code will not work

Rich (BB code):
Option Compare Text

Private Sub workbook_open()

Dim Arr() As Variant, Flag As Boolean
Arr = Array("mse330 laptop", "Mike") ' <--- change the names here

For x = LBound(Arr) To UBound(Arr)
    If Environ("Username") = Arr(x) Then
        Flag = True
        Exit For
    End If
Next x

If Flag = False Then
    MsgBox Environ("Username") & ", you don't have permission to access this file !", vbExclamation, "Warning"
    ActiveWorkbook.Close False
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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