Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a User Name On A Passowrd Protected Document 2

Status
Not open for further replies.

ooch1

MIS
Nov 4, 2003
190
GB
Hello,

Basically, we have a report that we want to keep to a particular user list.

Ideally what i would like to do is have a message box that each person has to fill in to access the document (preferably with there own password)and then prints/stores their name on the document.

I don't really no where to start with this or even if it possible, so was just hoping that some of you experts can point me in the right direction (in terms of process)and i will then attempt to code it all up?

Cheers

OOch
 
I should also add that this is all within excel.

Good luck

OOch
 
Have you tried to use

Environ("USERNAME")
 
If you use ENVIRON("Username") - which is probably the best way to do this - OK, someone gets the messagebox asking for their username. They enter it. What are you going to do?

You will need a hard coded list to use logic with. IF the entered username is on the list...OK, the files opens. If not, the file does not open.

Extend this thought (design) further). You do not need the USER to enter the ENVIRON("Username"). You can pick that up programmatically. Someone selects the file to open, as part of the opening event, you programmatically pick up the username, check against you list. IF it is there, the file opens, if it is not, message saying, nope you are not on the list.

If you want a second level, then sure, have each person on the list also enter a password. Make a hidden sheet that records those passwords. Then you can:

check against ENVIRON("Username") programmatically;
IF OK;
Ask for a password
IF never entered before
accept and record it
open file
ELSE
IF record exists THEN
open file
ELSE
ask again

This is NOT to say that a serious hacker could not bypass this....they can.

Gerry
See my Paintings and Sculpture
 
This is as crude as it gets... just playing around.
Users must have macros enabled by default and not be savvy enough to hit ctrl+break

Another option is to lock all of the cells and unlock it through the code. Then if they don't proceed through the code they can not modify anything.

Code:
Private Sub Workbook_Open()

On Error GoTo ProcFail

Dim strUser As String
Dim strPassword As String
Dim blnAccess As Boolean

strUser = InputBox("Enter user name", "", "")
strPassword = InputBox("Enter password", "", "")
blnAccess = False

Select Case strUser
   Case "Fake"
        If strPassword = "123" Then blnAccess = True
   Case "Other People"
        If strPassword = "321" Then blnAccess = True
End Select

If blnAccess Then
    'Add the name to the login sheet here
    Else: GoTo ProcFail
End If

Exit Sub

ProcFail:

ActiveWorkbook.Close
Application.Quit

End Sub


End Sub

The early bird gets the worm, but the second mouse gets the cheese.
 
1. As stated in my post, you do not need to ask for username. You can pick up their username (either their actual logon name, or their Office registered name...but the latter is too easy to get/change) programmatically. Or, if you really want to, you could ask for some sort of name, one that you assign to them.

2.
Code:
strUser = InputBox("Enter user name", "", "")
strPassword = InputBox("Enter password", "", "")

Select Case strUser
   Case "Fake"
        If strPassword = "123" Then blnAccess = True
   Case "Other People"
        If strPassword = "321" Then blnAccess = True
End Select
requires either the specific strings "Fake" or "Other People" - otherwise the boolean remains False. I realize these are examples, but it emphasizes that in order to function, there has to be a hard coded list somewhere to perform logic against.

Gerry
See my Paintings and Sculpture
 
Guys,

Although i haven't implemented the suggestions yet, i think that this help will prove invaluable.
At the end of the day, all we are trying to do is trying to add more control to circulation of confidential information. So producing a list of people to use the document will not be a problem at all.

No doubt i will be back on board with implemtnation problems in the next couple of days, but in the meantime thank you ever so much for your help.

OOch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top