LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Protecting Worksheets Problem


To explain i have the ProtectSheet Sub as a macro to lock the worksheet,
enable only selection of the unlocked cells, and locking the workbooks so
they cant unhide any other worksheets. UnprotectSheet unlocks all this.
ProtectSheetCells iand Unprotect Cell is mainly for check boxes that i have
controlling certain cells, it allows the the cell to become unlocked and then
locked again after the procedure is done.

My problem is within the ProtectSheetCells. With my code down below. I am
getting a "Run time error '5': Invalid procedure Call or Agrument", then it
highlights theThe Activeworkbook.protect line. So what am i doing wrong??

Thanks in Advance for the help!!!

Andy

--------------START OF CODE--------------------------
Option Explicit

'Ctrl+L Locks Sheet and Workbook with inputed password
Public Static Sub ProtectSheet()
Static StrPassword1 As String
Static StrPassword2 As String
Dim StrPass1 As Range

StrPassword1 = InputBox("Type a password")
StrPassword2 = InputBox("Re-type Password")
Set StrPass1 = Worksheets("BID RECAP SUMMARY").Range("A160")

If StrPassword1 < StrPassword2 Then 'VERIFIES PASSWORD
MsgBox ("Passwords didnt match, please try again.")
Else
StrPass1 = StrPassword1
ActiveSheet.Protect Password:=StrPassword1, DrawingObjects:=True, _
Contents:=True, Scenarios:=True 'LOCK SHEET FROM CHANGES
ActiveWorkbook.Protect Password:=StrPassword1, Structu=True 'LOCKS
WORKBOOK
ActiveSheet.EnableSelection = xlUnlockedCells 'LOCKS CELLS THAT CANT BE
SELECTED
MsgBox ("Password is set as " & StrPassword1)
End If

End Sub

'Ctrl+Shift+L UnLocks Sheet and Workbook with inputed password\
Public Static Sub UnProtectSheet()
Dim StrPassword As String
Dim StrPassword1 As Range

'STORE THE PASSWORD AT THE LOCATION BELOW TO BE USED WITH OTHER CODE
Set StrPassword1 = Worksheets("BID RECAP SUMMARY").Range("A160")

'INPUT PASSWORD TO UNLOCK SHEET AND WORKBOOK
StrPassword = InputBox("Type password to remove protection." &
vbCrLf & " Password is " & StrPassword1)
If LCase(StrPassword) < LCase(StrPassword1) Then Exit Sub
ActiveSheet.Unprotect Password:=StrPassword
ActiveWorkbook.Unprotect Password:=StrPassword

End Sub

'PROTECTS SHEET AND WORKBOOK USED FOR CHECKBOXES
Public Sub ProtectSheetCell()
Dim StrPass11 As Range

'SETS LOCATION OF PASSWORD
Set StrPass11 = Worksheets("BID RECAP SUMMARY").Range("A160")

'LOCKS SHEET AND WORKBOOK BASED ON PASSWORD IN SET LOCATION ABOVE
ActiveSheet.Protect Password:=StrPass11, DrawingObjects:=True, _
Contents:=True, Scenarios:=True
ActiveWorkbook.Protect Password:=StrPass11, Structu=True
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub

'UNPROTECTS SHEET AND WORKBOOK USED FOR CHECKBOXES
Public Sub UnProtectSheetCell()
Dim StrPass As Range

'SETS LOCATION OF PASSWORD
Set StrPass = Worksheets("BID RECAP SUMMARY").Range("A160")

'UNLOCKS SHEET AND WORKBOOK BASED ON PASSWORD IN SET LOCATION ABOVE
ActiveSheet.Unprotect Password:=StrPass
ActiveWorkbook.Unprotect Password:=StrPass

End Sub
--------------END OF CODE--------------------------
 
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
protecting worksheets Anthony Excel Worksheet Functions 1 July 27th 08 10:59 PM
Protecting Worksheets Pistols14 Excel Discussion (Misc queries) 7 November 27th 07 10:14 AM
Protecting Worksheets Kaitlin.uk Excel Discussion (Misc queries) 1 January 18th 07 02:21 PM
Protecting worksheets keiron James Excel Worksheet Functions 1 September 13th 06 04:23 PM
Protecting Worksheets Kathy081403 Excel Worksheet Functions 2 January 12th 06 12:56 AM


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

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"