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
 
What isn't working? That works fine for me - I can't change anything in the yellow box because my username is not in MySecretSheet

If I put my username in MySecretSheet, I can edit inside the yellow box

The code won't appear to do anything if you are an authorised user - your username is in MySecretSheet
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Just came acroos this thread and the code is brilliant. I've been trying to come up with a way of only letting certain users alter spreadsheets without having to have an annoying Read only Password. That people have to keep secret and I have to change if it gets known. As everyone who shares the spreadsheets I use have to log on with a username and password, just having it check the username seems plenty secure for me. Thank you very much for your brilliance.
 
Upvote 0
I was about to post the same issue. I get a Run time error 91 " Object variable or with block variable not set" This occurs on the oRng.Select line which is after the unauthorised user clicks OK to the message box. If you are authorised you get no error message.
 
Upvote 0
Try:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)




    If Not Intersect(Target, Range("H45:M47")) Is Nothing Then '''sets which cell(s) to work with
        'Use the above line to set a range of cells by changing ("A1") to your range say ("B4:D12")
        If Not isPermitted() Then
            MsgBox "You don't have permission to edit here"
            If oRng Is Nothing Then Set oRng = Range("A1")
            oRng.Select
        End If
    Else
        Set oRng = Target
    End If
    
    
End Sub
 
Upvote 0
perfect. The error message has gone and at the end of unauthenticated process the user goes to A1 cell!

Thanks
 
Upvote 0
Try:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)




    If Not Intersect(Target, Range("H45:M47")) Is Nothing Then '''sets which cell(s) to work with
        'Use the above line to set a range of cells by changing ("A1") to your range say ("B4:D12")
        If Not isPermitted() Then
            MsgBox "You don't have permission to edit here"
            If oRng Is Nothing Then Set oRng = Range("A1")
            oRng.Select
        End If
    Else
        Set oRng = Target
    End If
    
    
End Sub


it works on windows machine but how can I get username on Macintosh machine?
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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