Use this code: Private Sub CommandButton1_Click() Dim A As Integer Dim Shts As Worksheet A = TextBox1.Value If A = 123 Then For Each Shts In ThisWorkbook.Worksheets Shts.Unprotect Password:=123 Next UserForm1.Hide Else For Each Shts In ThisWorkbook.Worksheets Shts.Protect Password:=123 Next UserForm1.Hide End If End Sub
On Wed, Mar 25, 2009 at 9:01 PM, suresh k <brave.sur...@gmail.com> wrote: > Hi All, > > Can anyone help on this error. Below is the code. > > Private Sub ok_Click() > Dim a As Integer > a = Val(text1.Text) > > If a = bp Then > For Each shts In ThisWorkbook.Worksheets > shts.Unprotect > ActiveWorkbook.Unprotect > UserForm1.Hide > End If > > If Not a Then > > ActiveWorkbook.Protect > For Each shts In ThisWorkbook.Worksheets > shts.Protect > Next > End If > > End Sub > > > > > --~--~---------~--~----~------------~-------~--~----~ ------------------------------------------------------------------------------------- Some important links for excel users: 1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at http://www.excelitems.com 2. Excel tutorials at http://www.excel-macros.blogspot.com 3. Learn VBA Macros at http://www.vbamacros.blogspot.com 4. Excel Tips and Tricks at http://exceldailytip.blogspot.com To post to this group, send email to excel-macros@googlegroups.com If you find any spam message in the group, please send an email to: Ayush Jain @ jainayus...@gmail.com or Ashish Jain @ 26may.1...@gmail.com ------------------------------------------------------------------------------------- -~----------~----~----~----~------~----~------~--~---