PDA

View Full Version : Create password for permanent access



av8tordude
01-25-2008, 04:50 PM
When opening a workbook, Is it possible to create a password for a user to have permanent, unrestricted access and not not be prompted for a password again?

Simon Lloyd
01-26-2008, 04:45 AM
Of course its possible, however it will have to be done using VBA, for this macro's will have to be enabled and the workbook NOT protected!

All i can see with that is problems, that said try adding this to your "Thisworkbook" module.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim i As Integer
For i = 1 To Sheets.Count
Sheets(i).Protect Password:="password"
Next i
End Sub
Private Sub Workbook_Open()
Dim i As Integer
If Environ("UserName") <> "Simon Lloyd" Then
MsgBox "Restricted access only"
Else:
For i = 1 To Sheets.Count
Sheets(i).Unprotect Password:="password"
Next i
End If
End Sub
this way only the user named in the code above will have unrestricted access.

lynnnow
01-26-2008, 05:37 AM
What's the difference in applicability of Application.UserName and Environ("UserName"). Please explain this since I usually use the Application.UserName function.

mikerickson
01-26-2008, 06:01 AM
I made a suggestion at the cross-post.
http://www.mrexcel.com/forum/showthread.php?t=300010&page=3

Simon Lloyd
01-26-2008, 07:09 AM
Thanks Mike, i see the Op hasn't explained here what his real intention was like the cross post it doesnt appear until the second page of threads, and i agree he has had an extensive reply there!

Simon Lloyd
01-26-2008, 07:14 AM
lynnnow, AFAIK Application.Username will give you the name of the user using the application (if they entered one on set up!) and environ("username") picks up the windows login name!

Hope this helps!

Bob Phillips
01-26-2008, 07:15 AM
What's the difference in applicability of Application.UserName and Environ("UserName"). Please explain this since I usually use the Application.UserName function.

Application.Username is an Excel setting, and can be changed in Tools>Options by the user.

Environ("Username") is a system variable that picks up the login name.

So the second is far more robust than the first - you should switch immediately.

Simon Lloyd
01-26-2008, 07:16 AM
Ouch!

av8tordude
01-26-2008, 07:32 AM
Hi everyone. Just woke up this morning. I posted my question last night b4 going to bed. So I didn't see any responses to my question before going to bed until this morning.:eek: As for cross-posting, I wasn't sure if I could reference another website onto this web-site. From the responses I've i received, apparently its OK.:thumb

As my intentions with the codes provided, My workbook is a trial workbook to allow users to try it. And if the like it, the buy the workbook. If not, the can delete it from the computer. If the try to circumvent the password after three chances to enter the correct password, the workbook is automatically rendered useless and deleted from their computer.

When the finish product is complete, I would like to post the complete code when I finish for others to reference.

Again, I asked for you patience and continue expert help.: pray2: I respect and praise all of your help :bow: :beerchug: