Macro Prompt to protect

  • Thread starter Thread starter ianripping
  • Start date Start date
I

ianripping

Is there a way so that when a user exits a workbook a promt comes up if
a certain sheet hasn't been protected?

Eg Sheet Name = "Index"

If index hasn't been protected then promt comes up asking for user to
enter a password to protect that sheet. If it is protected then the
worksheet carry's on exiting.
 
If you mean closing the workbook, just use the BeforeClose Event. You can
check if the sheet is protected for content by looking at the

Worksheets("Special").ProtectContents property
If it is false, the sheet isn't protected. If you want to prompt for a
password, use the inputbox or build a userform to do this. To see the code
for protecting a sheet, turn on the macro recorder while you do it manually.
 
Hi

Paste in the ThisWorkbook module:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Pwd As String
Dim Bsaved As Boolean
If Sheets("Index").ProtectContents = False Then
Bsaved = Me.Saved
Pwd = InputBox("Please enter password for sheet Index:")
If Pwd = "" Then
Cancel = True
Else
Sheets("Index").Protect (Pwd)
If Bsaved Then Me.Save
End If
End If
End Sub
 
That is some nice code Harald. Is it possible to make the characters t
appear as "*" instead of the word being visible when it is bein
inputted by the user
 
With readily built in functionality, no. The Inputbox doesn't support this
with a setting. Only the userform textbox has this as a readily accessible
built in capability.
 
I haven't tested (or ever seen) this one in action, but check
http://www.xcelfiles.com/API_09.html
for a possible solution.

Remember also, defaut Excel behavior is "Please type password again", to
ensure that the user doesn't misspell or Jack Daniels-induced make things up
when typing. With **** it's more important than when you can see what you're
doing.

HTH. Best wishes Harald
 
I am sure Ian will have that up and running in no time.

--
Regards,
Tom Ogilvy

Harald Staff said:
I haven't tested (or ever seen) this one in action, but check
http://www.xcelfiles.com/API_09.html
for a possible solution.

Remember also, defaut Excel behavior is "Please type password again", to
ensure that the user doesn't misspell or Jack Daniels-induced make things up
when typing. With **** it's more important than when you can see what you're
doing.

HTH. Best wishes Harald
 
Tom Ogilvy said:
I am sure Ian will have that up and running in no time.

Hopefully not responding "I had a lot of files on my C drive and now they're
all gone" :-)

Best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top