Password Code in VBA

CY078

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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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
 
Upvote 0

Forum statistics

Threads
1,212,929
Messages
6,110,743
Members
448,295
Latest member
Uzair Tahir Khan

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