MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

VBA Passwords

  Asked By: Bamah    Date: Nov 03    Category: MS Office    Views: 1320

I have protected my sheet with a password that I need to be able to
type into one of the forms to unprotect it for editing.

I have 2 questions about this:

1) how do I get excel/VBA to type asterisks (*) for each of the
characters in the password as it is being typed into the form?

2) once the form is unprotected, how do I allow for editing and then
when done or on exiting reprotect the sheet with the password?



5 Answers Found

Answer #1    Answered By: Rosie Hughes     Answered On: Nov 03

When you say "form" do you MEAN "form" as in Userform
or do you have a worksheet that resembles a form?

if you're using a Userform,
use a TextBox for the entry.
In the Properties panel of the textbox, there is a Password Character property.
Put a "*" there.
You can create a Workbook_BeforeClose event,
or a Worksheet_Deactivate event, or both
that could be used to re-protect the sheet.
You might want to include it instead in a Workbook_BeforeSave event
so that the user cannot save it in an unprotected state.
Of course, if you're using a worksheet template instead of a UserForm,
we'll have to look closer at the change events.

Answer #2    Answered By: Freya Brown     Answered On: Nov 03

Yes, this helps a great deal. I have created userforms for my
spreadsheet for data entry, sorting, and modifications, but had no
idea how to handle the document once unprotected from the
modification userform. This helps. Thank you. I will look into the
workbook_beforesave & workbook_beforeclose events. Thank you.

Answer #3    Answered By: James Wakner     Answered On: Nov 09
Didn't find what you were looking for? Find more on VBA Passwords Or get search suggestion and latest updates.