Windows user name and password for authentication

tsawyer73

New Member
Joined
Mar 20, 2013
Messages
21
I'd like to protect a small area in the excel sheet. Example H45:M47 where the user should put his/her windows username and password as authentication method through a VBA userform window.

I'm not a VBA expert due to that fact the full step by step VBA code and setup will appreciate!

Thanks
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
How do you propose to check whether the username and password entered is correct when you don't have access to this information?

You'd be better off detecting the username and allowing changes based on it.

eg

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, [H45:M47]) Is Nothing Then

    If Not Environ("USERNAME") = "user" Then  '<=== The username of the person who is 
allowed to edit it

        [A1].Select
        
    End If

End If
   
End Sub
 
Upvote 0
And where shall I put this code above?

Alt + F11
Double click relevant sheet on left hand side
Paste code in big white area on right hand side
Make sure that "user" is whatever username you want to allow access to the cells
 
Upvote 0
Thanks but I think that function is different what I'd like to implement with VBA. At this time my VBA script contains a modified version of this script (VBA Express : Excel - Protect cell or cells on sheet without protecting sheet) As you can see the VBA can protect and cell with fixed password. My final goal little bit different than this method because the file will handle by multiple users. Tha's why I need the windows username and password authentication instead of any fixed username and password information.
 
Upvote 0
Are you seriously considering storing a users Windows Login name (which you can get using the ENVIRON() function in any case) and their password in an Excel workbook or VBA code?

Have you run this past your IT department...?
 
Upvote 0
Thanks but I think that function is different what I'd like to implement with VBA. At this time my VBA script contains a modified version of this script (VBA Express : Excel - Protect cell or cells on sheet without protecting sheet) As you can see the VBA can protect and cell with fixed password. My final goal little bit different than this method because the file will handle by multiple users. Tha's why I need the windows username and password authentication instead of any fixed username and password information.

You need to re-think your plans.

Happy to help provide alternate solutions which would involve:

(1) Detecting the user that is logged on
(2) Assigning spreadsheet permissions based on this against a table of users/permissions that you maintain in the spreadsheet
 
Upvote 0
As I see this code:
can handle the windows username but I know nothing about the windows password :(


Declare Function IGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal sBuffer As String, lSize As Long) As LongFunction GetUserName() As String On Error Resume Next Dim sBuffer As String Dim lSize As Long Dim x As Long sBuffer = Space$(32) lSize = Len(sBuffer) x = IGetUserName(sBuffer, lSize) GetUserName = left$(sBuffer, lSize - 1)End Function
</pre>
 
Upvote 0
So if we can detect the user who is logged on how can we use this for authentication process?
If I choose the 2nd option how can I hide the table with username/password list?

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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
Back
Top