#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Protection

I have a workbook that consists of approx. 60
worksheets. Each worksheet is individually password
protected with the same password. At times, someone
forgets to protect one worksheet before closing the
file. Is there a way to prompt the user with a message
(I'll assume it requires VBA code) on closing if he or
she forgets to password protect one or more of the
worksheets?

Thank you
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Protection

I think I'd let the user close without protecting the sheets.

But apply the password the next time the workbook was opened:

Option Explicit
Sub auto_open()
Dim myPwd As String
Dim wks As Worksheet

myPwd = "whateveryouwant"

For Each wks In ThisWorkbook.Worksheets
If wks.ProtectContents _
Or wks.ProtectDrawingObjects _
Or wks.ProtectScenarios Then
'already protected
Else
wks.Protect Password:=myPwd
End If
Next wks

End Sub

The bad news is that if the user disables macros (or just stops auto_open), you
could be in trouble.

Karen wrote:

I have a workbook that consists of approx. 60
worksheets. Each worksheet is individually password
protected with the same password. At times, someone
forgets to protect one worksheet before closing the
file. Is there a way to prompt the user with a message
(I'll assume it requires VBA code) on closing if he or
she forgets to password protect one or more of the
worksheets?

Thank you


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Protection

Hi

Place this in the ThisWorkbook module:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim sh As Worksheet
For Each sh In Me.Worksheets
If sh.ProtectContents = False Then
Cancel = True
MsgBox sh.Name & " is not protected.", _
vbInformation, "Cancelling close"
Exit Sub
End If
Next
End Sub

The above is the most annoying solution. If the code knows the password then
it might use it to protect instead of forcing the poor girl to do it
manually.

For Each sh In Me.Worksheets
If sh.ProtectContents = False Then
sh.Protect "Very Secret Words"
End If
Next

HTH. Best wishes Harald

"Karen" skrev i melding
...
I have a workbook that consists of approx. 60
worksheets. Each worksheet is individually password
protected with the same password. At times, someone
forgets to protect one worksheet before closing the
file. Is there a way to prompt the user with a message
(I'll assume it requires VBA code) on closing if he or
she forgets to password protect one or more of the
worksheets?

Thank you



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Data Protection Best Practice: AKA: Real Sheet Protection Mushman(Woof!)[_2_] Excel Discussion (Misc queries) 4 December 30th 09 01:20 AM
Excel Data Protection- AKA: Sheet/Macro Password Protection Mushman(Woof!) Setting up and Configuration of Excel 0 December 29th 09 06:50 AM
WS Protection: Different Levels of Protection on Different Ranges Carmi Excel Discussion (Misc queries) 4 August 31st 07 02:26 PM
Cell Protection vs. Worksheet Protection kmwhitt Excel Discussion (Misc queries) 4 September 24th 06 02:37 AM
Worksheet protection is gone and only wokbook protection can be se Eric C. Excel Discussion (Misc queries) 4 May 2nd 06 04:50 PM


All times are GMT +1. The time now is 01:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"