creating a username and password box

K

kil

do anyone know how to create a username/password box with
a userform in microsoft Excel, I tried creating one but
not able to get the excel to make decision of who is
accessing, I don't want to use excel protect book, where
it will exposed all my work to every user,


here is my cod

if txtname= user

then workbookfiance.activate


am I'm on the right track?
 
B

Bob Phillips

You will need to save the allowable users in a list somewhere and compare
the current user against that.

You can get the login user with

Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long

Public Function UserName() As String
Dim sName As String * 256
Dim cChars As Long
cChars = 256
If GetUserName(sName, cChars) Then
UserName = Left$(sName, cChars - 1)
End If
End Function

Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.LeftFooter = UserName
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top