LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Unprotecting/Reprotecting

You could put the code in Module1 (say we call it UnLockEm) and to allow you
to work with one sheet at a time let's add a parameter for the worksheet
name. Make it a Public Sub so it can be called from any other module. It
appears from your post that the user will not know the password so you would
need to hard code it, which does open it up to anyone with the knowledge of
how to get into VBA, so that is a concern you will have to decide about:

Public Sub UnLockEm(ThisSheetName as String)
With Sheets(ThisSheetName)
.Unprotect("Password")
.Range("C4").FormulaR1C1 = "cc"
.Protect("Password")
End With
End Sub

To link it to your Worksheet event procedures, just make the call as shown
in this example:
Private Sub Worksheet_Change(ByVal Target as Range)
....
UnLockEm(Me.Name)
....
End Sub

"Adam" wrote:

I have a VBA code in Module1 of a workbook which protects all the sheets with
the same password. The code is
Sub LockEm()
Dim i As Long
Dim PW As String
Dim WS As Worksheet
PW = InputBox("Enter password to protect all sheets:")
On Error GoTo MyErr
For Each WS In ActiveWorkbook.Worksheets
WS.Protect (PW)
Next
MsgBox i & " errors while protecting", vbInformation
Exit Sub
MyErr:
i = i + 1
Resume Next
End Sub

Now, I have a macro in the same module in which I would like to unprotect
the sheet with the password entered when protecting all the sheet, execute
some activities and then reprotect it with the same password, i.e. lets say I
i have the macro
Sub xxx()
Range("C4").Select
ActiveCell.FormulaR1C1 = "cc"
End Sub

Where and how do I enter the code?
I assume I need to make PW public or something (I'm quite new at VBA)

Secondly, I would like to apply the same thing as above to a worksheet event
that I have in a specific sheet

Any ideas?
Thanks


 
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 a worksheet Jessica Excel Worksheet Functions 8 August 21st 08 06:43 PM
Unprotecting a VBA Project Anthony Cuttitta Jr. Excel Programming 13 September 30th 04 06:28 AM
Unprotecting! Joseph Excel Programming 1 August 3rd 04 02:18 PM
Unprotecting! Joseph Excel Programming 1 August 2nd 04 04:18 PM
Unprotecting! Joseph Excel Programming 1 August 2nd 04 03:13 PM


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