Excel Book Login and PW question

Johnzea

New Member
Joined
Apr 5, 2019
Messages
23
Does anyone have any tips on the best way's to protect your workbook with a Login? Maybe an up front Form and Module?
Thank you for any help...

Johnzea
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I don't know if it's the best way, but this would work. The code should be placed in the "ThisWorkbook" module. In case you miss it, the current Password is "abcd". It adds a blank page so that the person opening the book cannot "peak" at the contents behind the InputBox...

Code:
Private Sub Workbook_Open()
    
    Dim pw As String
    Application.DisplayAlerts = False
    Worksheets.Add
    pw = InputBox("Please enter password")
    If Not pw = "abcd" Then
        MsgBox "You have entered an incorrect password" & _
            vbNewLine & vbNewLine & "This workbook will now close."
        ActiveSheet.Delete
        ThisWorkbook.Close
        Exit Sub
    End If
    ActiveSheet.Delete
    Application.DisplayAlerts = True
    
End Sub
 
Upvote 0
An easy workaround for the supplied code would be to simply turn macros off before opening the workbook.
Have you tried using "protect workbook" found in the file tab and supplying the password through that instead?
 
Upvote 0
You could use a UserForm. I have done that many times. Here is an example that I wrote. you can apply xlVeryHidden to all the sheets when the workbook opens. then apply xlVisible to them when a valid password is entered. Try entering "JZ2222" when form shows. It will display "Welcome John Zea..."

The Admin password is currently set to "Admin123" for both the workbook and VBA.

Trevor Easton at onlinepclearning.com has some great videos on this. I actually used some of his code in this project.
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,954
Members
448,535
Latest member
alrossman

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