Hi Jerry, I think my head hurts. I'll explain the sequence of events.
1. I open up the file in it's master state (no client data).
2. I enter the client name which creates paths for the folder and file to
follow later
3. I click a button to select one of six macros to run, depending on client
type
4. The macro from 3. (above) performs varios functions on the three sheets
in the book to get into the state I require for the client type (different
formulas, deletes rows etc)
5. I then save the file in the client's folder and email it out to them so
that they can enter data and send it back to me.
The lock/unlock cells routine is so that the client can't enter unnecessary
data (e.g if at the same address for 3 years I don't need the previous
address and so the cells for the previous address get locked). This of course
has to be in the sheet code for 'PERSONAL' which is now as follows:
Private Sub Worksheet_Calculate()
ActiveSheet.UNPROTECT
If Range("add.years.1").Value >= 3 Then
Range("previous.address.1").Locked = True
Else
'< 3 processing
Range("previous.address.1").Locked = False
' IT TRIPS UP ON THE LINE ABOVE when I hit the macro button
End If
If Range("yrs.position.1").Value >= 3 Then
Range("previous.job.1").Locked = True
Else
'< 3 processing
Range("previous.job.1").Locked = False
End If
If Range("nm.first.2").Value < 1 Then
Range("client.2.1").Locked = True
Range("client.2.2").Locked = True
Else
'< 3 processing
Range("client.2.1").Locked = False
Range("client.2.2").Locked = False
ActiveWindow.ScrollRow = 9
If Range("add.years.2").Value >= 3 Then
Range("previous.address.2").Locked = True
Else
'< 3 processing
Range("previous.address.2").Locked = False
End If
If Range("yrs.position.2").Value >= 3 Then
Range("previous.job.2").Locked = True
Else
'< 3 processing
Range("previous.job.2").Locked = False
End If
End If
ActiveSheet.Protect
End Sub
You will note that I have removed Activesheet altogether, and not replaced
it with ThisWorksheet. It seems unnecessary, and it does work like this. It
did NOT like having ThisWorksheet.UNPROTECT as the second line (it didn't
seem to know what I meant).
So far all that works when I pretend to be the client filling in data, but
this step actually comes after I hit the macro button to set up the client
type. The code for that particular button is as follows:
Sub NEW_CLIENT()
Sheets("Instructions").Visible = True
Sheets("Privacy Act").Visible = True
Sheets("PERSONAL").Select
ActiveSheet.UNPROTECT
Range("virgin").FormulaR1C1 = ""
Application.DisplayAlerts = False
ActiveSheet.UNPROTECT
ActiveWorkbook.BreakLink Name:=Range("Falsepath.97PREVIOUS"),
Type:=xlExcelLinks
ActiveSheet.UNPROTECT
ActiveWorkbook.BreakLink Name:=Range("Path.DATAFILE"), Type:=xlExcelLinks
ActiveSheet.UNPROTECT
ActiveWorkbook.BreakLink Name:=Range("Falsepath.SNAPSHOT"),
Type:=xlExcelLinks
ActiveSheet.UNPROTECT
ActiveWorkbook.BreakLink Name:=Range("Path.DD"), Type:=xlExcelLinks
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Application.DisplayAlerts = True
'COPY "LIABILITIES" FORMULAS
Sheets("NEW LIABILITIES").Select
Sheets("NEW LIABILITIES").Activate
Rows("60:238").Delete
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollRow = 10
'IT WORKS FINE UNTIL THE FOLLOWING LINE:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Range("J21").Select
BLAH BLAH BLAH to End Sub
When it gets to the ActiveSheet.Protect it fails , but it debugs to the
Private Sub in 'PERSONAL' even though its on the 'NEW LIABILITIES ' sheet (I
have marked as "IT TRIPS UP ON THE LINE ABOVE". There is no other sheet code
in any other sheet except 'PERSONAL'
I know that's a lot to digest for you. In other words I'm executing a macro
that tootles off to another sheet, does most of it's stuff, but fails when it
tries to protect that sheet (not 'PERSONAL'), but it debugs to the sheetcode
in 'PERSONAL'. I have changed the Activesheet to be 'NEW LIABILITIES' as you
can see.
Jerry, your help is greatly appreciated.
Regards, Brett