Protecting an Active Work Book (1 Viewer)

AshikHusein

Registered User.
Local time
Today, 10:44
Joined
Feb 7, 2003
Messages
147
Hello,

I am trying to protect a worksheet from being modified.

If it is opened by certain users (I am getting the systems username) it should allow editing. For others using the workbook, it should protect the workbook from any modifications.

I am using the following VBA code but it does nothing:

ActiveWorkbook.Protect Password:="xxxxxxx"

I would like to request help in understanding what I am doing wrong here.

Thanking you in advance.
 

ghudson

Registered User.
Local time
Today, 10:44
Joined
Jun 8, 2002
Messages
6,194
What event are you running the code in? I suggest the Auto_Open event to run your code to test who the user is and what action to take on which worksheet and what you want do to that worksheet.

You can use the record macro function to get most of your code and then fine tune it once you understand what you want and were to put it.
 

HaHoBe

Locomotive Breath
Local time
Today, 16:44
Joined
Mar 1, 2002
Messages
233
Hi, AshikHusein,

first get Environ("Username"), then do a Select Case with this value with something like

Code:
    With ThisWorkbook
        .Saved = True
        .ChangeFileAccess xlReadOnly
    End With
for all those users who shouldn´t modify the workbook.

Depending on the number of people I would recommend to list the names for all those who should be able to modify the workbook (no code line) and assign the code to the Case Else branch. ;) I would also recommend to change the values of the username to either UCase oder LCase for this check.

Ciao,
Holger
 

AshikHusein

Registered User.
Local time
Today, 10:44
Joined
Feb 7, 2003
Messages
147
Thank you Gudson and HaHoBe

By the way, HaHoBe I am also a fan of Jetro Tull!!
 

Users who are viewing this thread

Top Bottom