different user question

viper

Active Member
Joined
Feb 15, 2002
Messages
382
What's the correct way to use vba to open a file as readonly? I've looked at the help in vb but can't get the code to work properly. I want to allow varied access to different users of my file. Some will have all access and others I want to limit to view only, no printing, changing, etc. I have my file set up now so that upon opening it disables the File menu, asks for a password before printing, I even have the main sheet hidden and requires a password before viewing, but this seems like alot of different things to add to a file instead of just allowing certain access to different users.

If I can just do something like:
dim name as string

name = Inputbox("Enter your name")
if name = "Joe" then
activeworkbook.open(readonly)
elseif
name = "Sara" then
activeworkbook.open
end if
something along those lines.

thanks,
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
You have to use the Workbooks.Open command, and then use the ReadOnly parameter:

Workbooks.Open(FileName,ReadOnly:=True)
 

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,123
Different point - if you are varying access by user...

If running Windows NT then rather than allow people to enter their name, use

USER = Environ("Username")

so USER would be "jbloggs" or "jb" etc...

You can then set the access rights from this. In short it's a lot more secure as no-one is able to "be" anyone else unless they know other peoples login codes to MS Office which is unlikely.
 

Forum statistics

Threads
1,144,120
Messages
5,722,596
Members
422,447
Latest member
knopp

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
Top