![]() |
|
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: Mar 2003
Posts: 8
|
Hello,
I need a macro that will load on opening of a spreadsheet that prompts for a username and password. Ideally I would be able to add new users and passwords with the macro but not completely necessary. I would need the username to then be copied somewhere into the spreadsheet so that I can run other macros that stamp entries with the specific username and date. Anyone have some code for a username/password login? I'm a bit new to the macro thing. Thanks, Brent :o |
|
|
|
|
|
#2 |
|
Join Date: Mar 2003
Posts: 8
|
In looking at past posts I'm thinking that the first thing I need to do is make a userform, so I made one with two textboxes (one username, one password), and three buttons (one "ok", one "cancel", and one "new user"). Now how do I get the userform to load on opening the macro and query either a protected spreadsheet for the username and passwords (in hidden fields or something for some protection) and work as a usual login? Sorry, I thought this would be alot simpler and I told my boss I could come up with something like this and now I'm kind of in a jam (not a programmer or anything, just a guy who works in a lab who thinks he knows excel).
thanks, brent :o |
|
|
|
|
|
#3 |
|
Join Date: Mar 2003
Posts: 8
|
Well I have come across some code from another post (sorry I don't remember whose it was, but thanks to whoever originally posted it). I have "username" as the name of my username textbox and "password" as the name of my password textbox in my userform. I made a worksheet named "password" and in cell A1 I have a username and in A2 I have a password. Same goes for B1 (another username) and B2 (another password). Now how do I tie all this together? I get a compile error of method or data member not found with the "txtpassword" part of UserForm2.txtPassword.Value = "" highlighted
Any and all help is extremely appreciated. =Brent Sub login() ' ' login Macro ' Dim Rng As Range Dim username As String Dim Password As String Dim x As Integer Set Rng = Worksheets("Password").Range("A1") x = 0 Do username = Rng.Offset(x, 0).Value If txtUserName2 = username Then Password = Rng.Offset(x, 1).Value Rng.Offset(x, 2).Value = Date If username <> Password Then MsgBox "New Passwords do not match", vbExclamation + vbOKCancel UserForm2.username.Value = "" UserForm2.Password.Value = "" Exit Do End If If txtPassword = Password Then Rng.Offset(x, 1).Value = username MsgBox "Password successfully changed", vbInformation UserForm2.Hide End If If txtPassword <> Password Then MsgBox "Incorrect Password Given, please enter the correct password.", vbCritical, "Password Error!" txtPassword.SetFocus UserForm2.txtPassword.Value = "" End If x = x + 1 Loop Until x > 17 End Sub ' |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|