Password Code in VBA

CY078

New Member
Joined
Nov 2, 2014
Messages
12
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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,662
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,136,771
Messages
5,677,635
Members
419,707
Latest member
Anna vib

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