Password question, but not a "how to crack" question.

jproffer

Well-known Member
Joined
Dec 15, 2004
Messages
2,647
Hi folks,

I wonder if anyone knows a way to determine if a worksheet is protected WITH a password vs. protected without a password. I know how to check for protection in general...but not how to figure out if there's a password attached to that protection.

Any insight/direction is greatly appreciated :)
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Re: Password questiion, but not a "how to crack" question.

I would say easy way is to try to unprotect it. If there is a password, it will prompt you for it. If there isn't one, it will simply unprotect it for you.
 
Upvote 0
Re: Password questiion, but not a "how to crack" question.

If you try to unprotect a worksheet and it ask for a password then it is password protected.
 
Upvote 0
Re: Password questiion, but not a "how to crack" question.

Roger that, but...little more info:

This is just for an informational listbox which lists the worksheets within a workbook. I just thought it would be nice to show "Has Password" or "No Password", but if there's no fairly simple way of determining that through VBA, then I won't worry about it.
 
Upvote 0
Re: Password questiion, but not a "how to crack" question.

I guess another idea would be to use that dialog to my advantage. If I can figure out how to trap the "enter password" dialog, cancel it, increment a counter and then something like:

Code:
If counter <> 0 Then 
     (listbox column).Value = "Has Password"
Else
     (listbox column).Value = "No Password"
End If

Maybe...

But as far as MY knowledge goes, I'm still where I started. How would one trap and cancel the "enter password" dialog when and if it pops up?
 
Upvote 0
Re: Password questiion, but not a "how to crack" question.

How about
Code:
Sub chkPword()
   Dim ws As Worksheet
   Dim Msg As String
   
   For Each ws In Worksheets
      On Error Resume Next
      ws.Unprotect ""
      On Error GoTo 0
      If ws.ProtectContents Then Msg = Msg & ws.Name
   Next ws
   MsgBox Msg
   
End Sub
 
Upvote 0
Re: Password questiion, but not a "how to crack" question.

Fluff and Scott T, thank you both for the ideas. They both worked perfectly.

EDIT: Ok, not quite perfectly. It unprotects sheets without passwords as the listbox loads. I see why, and I'd like to try to figure out how to just "test for a password" only, not necessarily unprotect anything without one.

BUT, I'd like to try to straighten it out on my own :) .

if I can't, I may be back.

Even still, you put me on the right path and I do appreciate that for sure.
 
Last edited:
Upvote 0
Re: Password questiion, but not a "how to crack" question.

Glad we could help & thanks for the feedback
 
Upvote 0
Re: Password questiion, but not a "how to crack" question.

EDIT: Ok, not quite perfectly. It unprotects sheets without passwords as the listbox loads. I see why, and I'd like to try to figure out how to just "test for a password" only, not necessarily unprotect anything without one.
In case it doesn't use password protection so that it unprotects the sheets, you could always add code back in there to re-protect them!;)
So then when the code finishes running, you really haven't changed the protection at all.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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