Password Code in VBA

CY078

New Member
Joined
Nov 2, 2014
Messages
15
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Sub protect_all_sheets()
top:
pass = InputBox("password?")
repass = InputBox("Verify Password")
If Not (pass = repass) Then
MsgBox "This is NOT the password !!!"
GoTo top
End If
For i = 1 To Worksheets.Count
If Worksheets(i).ProtectContents = True Then GoTo oops
Next
For Each s In ActiveWorkbook.Worksheets
s.Protect Password:=pass, AllowFiltering:=True
Next
Exit Sub
oops: MsgBox "I think you have some sheets that are already protected. Please unprotect all sheets then running this Macro."
End Sub

Hi All

Im using Excel MS 365 MSO (16.0.13628.20318) and have a question about a VBA code i've used.

The code is as above and I tried to search for the answer to no avail. Basically as I am typing in the password ... it can be seen (so if someone is watching while I edit then they can see the password when its typed in).

How can I code it as to not show whilst typing.

Apologies as I am only starting out with code writing ... my end goal is to "Protect all tabs" / "allow some editing" with a macro

Thanks :)
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,791
Office Version
  1. 2019
Platform
  1. Windows
Hi,
while it is possible to mask the characters entered in an InputBox it is quite complex - a simpler solution would be to use a UserForm with Textboxes where you can simply set a the password character property.

an example how to do this can be found here: Excel Userform Login - Online PC Learning

Dave
 

Forum statistics

Threads
1,141,413
Messages
5,706,301
Members
421,441
Latest member
VapesRub

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
Top