Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default Unprotecting worksheets only if you have the password

Hi,

I have a macro button that unprotects each worksheet in my workbook. But I
want the user only to have the ability to unprotect each worksheet after a
code is entered. The problem is that if the user chooses "Cancel" or the "X"
button to close the dialogue box, the worksheets proceed to unprotect. I've
taken care of the event that a user enters in an incorrect amount. How do I
prevent the user to unprotect each worksheet if they don't have the correct
password?

Here is my code:

Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
ActiveSheet.Unprotect
On Error GoTo Finish
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password:="1111"
Next ws
Finish:
Application.ScreenUpdating = True
End Sub

Thanks in advance,

--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default Unprotecting worksheets only if you have the password

Hi Mike,

How can I have VBA just provide one dialoque box asking the user to provide
a password without Excel cycling through each worksheet to unprotect by
calling up the same dialogue box....

Thanks,
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Mike H" wrote:

Hi,

When you say 'Code' I assume you mean the sheet protection password. If so
modify your code thus

Private Sub CommandButton2_Click()
On Error GoTo Finish
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect
Next ws
Finish:
End Sub


Mike

"klysell" wrote:

Hi,

I have a macro button that unprotects each worksheet in my workbook. But I
want the user only to have the ability to unprotect each worksheet after a
code is entered. The problem is that if the user chooses "Cancel" or the "X"
button to close the dialogue box, the worksheets proceed to unprotect. I've
taken care of the event that a user enters in an incorrect amount. How do I
prevent the user to unprotect each worksheet if they don't have the correct
password?

Here is my code:

Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
ActiveSheet.Unprotect
On Error GoTo Finish
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password:="1111"
Next ws
Finish:
Application.ScreenUpdating = True
End Sub

Thanks in advance,

--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Unprotecting worksheets only if you have the password

Provide an InputBox to the user and compare that string to the actual pwd
string. If it matches then use it to unprotect the sheets, if no match then
show a MessageBox that the pwd was wrong and Exit Sub.

Mike F
"klysell" wrote in message
...
Hi Mike,

How can I have VBA just provide one dialoque box asking the user to
provide
a password without Excel cycling through each worksheet to unprotect by
calling up the same dialogue box....

Thanks,
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Mike H" wrote:

Hi,

When you say 'Code' I assume you mean the sheet protection password. If
so
modify your code thus

Private Sub CommandButton2_Click()
On Error GoTo Finish
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect
Next ws
Finish:
End Sub


Mike

"klysell" wrote:

Hi,

I have a macro button that unprotects each worksheet in my workbook.
But I
want the user only to have the ability to unprotect each worksheet
after a
code is entered. The problem is that if the user chooses "Cancel" or
the "X"
button to close the dialogue box, the worksheets proceed to unprotect.
I've
taken care of the event that a user enters in an incorrect amount. How
do I
prevent the user to unprotect each worksheet if they don't have the
correct
password?

Here is my code:

Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
ActiveSheet.Unprotect
On Error GoTo Finish
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password:="1111"
Next ws
Finish:
Application.ScreenUpdating = True
End Sub

Thanks in advance,

--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557



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
Unprotecting worksheets only if you have the password Mike H Excel Programming 1 August 17th 07 01:53 AM
Unprotecting (with password) the activeworkbook Dave Peterson Excel Programming 0 January 10th 07 03:54 PM
Macro asking for a password twice when unprotecting sheet Tim Whitley[_3_] Excel Programming 2 February 20th 06 04:51 PM
Password Protecting/Unprotecting Via Code MWS Excel Programming 3 December 12th 05 03:21 PM
Unprotecting password protected workbook Vnagpal Excel Discussion (Misc queries) 1 December 10th 05 06:33 AM


All times are GMT +1. The time now is 08:55 AM.

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

About Us

"It's about Microsoft Excel"