Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default macro button to unprotect entire workbook (used after password ent

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: 417
Default macro button to unprotect entire workbook (used after password ent

I used the following code, and it seems to work fine:

Public Sub UnprotectAllWorksheets()
Const strMsgBoxTitle As String = "Unprotect All Worksheets"
Dim ws As Worksheet
Dim strPassword As String

strPassword = InputBox(Prompt:="Enter the password:", _
Title:=strMsgBoxTitle)

If strPassword = "1111" _
Then
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password:=strPassword
Next ws
MsgBox "All worksheets unprotected.", _
vbInformation + vbOKOnly, _
strMsgBoxTitle
Else
MsgBox "Password failed.", _
vbCritical + vbOKOnly, _
strMsgBoxTitle
End If
End Sub

I placed a simple button from the Forms toolbar on the first worksheet,
then called the macro straight from there. I didn't use a UserForm, to
eliminate extra work.

If you insist on using a UserForm (designed in the VBA editor), then you
may have to tell us more details about how this form is displayed, what
other buttons are there, which one is the default, etc. Your
"CommandButton2_Click" routine must be the default button or something.
I think a UserForm is more complicated that what you actually need.
--
Regards,
Bill Renaud


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default macro button to unprotect entire workbook (used after password

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


"Bill Renaud" wrote:

I used the following code, and it seems to work fine:

Public Sub UnprotectAllWorksheets()
Const strMsgBoxTitle As String = "Unprotect All Worksheets"
Dim ws As Worksheet
Dim strPassword As String

strPassword = InputBox(Prompt:="Enter the password:", _
Title:=strMsgBoxTitle)

If strPassword = "1111" _
Then
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password:=strPassword
Next ws
MsgBox "All worksheets unprotected.", _
vbInformation + vbOKOnly, _
strMsgBoxTitle
Else
MsgBox "Password failed.", _
vbCritical + vbOKOnly, _
strMsgBoxTitle
End If
End Sub

I placed a simple button from the Forms toolbar on the first worksheet,
then called the macro straight from there. I didn't use a UserForm, to
eliminate extra work.

If you insist on using a UserForm (designed in the VBA editor), then you
may have to tell us more details about how this form is displayed, what
other buttons are there, which one is the default, etc. Your
"CommandButton2_Click" routine must be the default button or something.
I think a UserForm is more complicated that what you actually need.
--
Regards,
Bill Renaud



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
Forgotten Password to Unprotect Workbook/sheet Brandon Excel Discussion (Misc queries) 10 April 4th 13 12:10 PM
How I unprotect my workbook if I failed to remember my password ShaF Malik Excel Worksheet Functions 2 July 5th 08 04:19 PM
How do I unprotect a workbook without the password? FJBSD Excel Discussion (Misc queries) 1 March 29th 08 11:49 PM
Record a macro which enters a password to unprotect a workbook Zeon Excel Programming 1 February 23rd 06 07:20 PM
Unprotect workbook without password Maria K Brickl Excel Programming 3 June 20th 05 06:08 PM


All times are GMT +1. The time now is 11:15 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"