Code not working in a PROTECTED Worksheet

  • Follow


I have the code below in a worksheet on a file in SharePoint. The worksheet 
is Protected so only unprotected Cells are selectable. The problem I am 
having is that when the sheet is protected I get an error on:
         Me.Rows("5:169").EntireRow.Hidden = False
and I know it is because on the protection because when I remove the 
protection from the sheet, the macro works fine. Is there a way around this 
problem?

Private Sub cmdCPA_Click()
Application.ScreenUpdating = False
    Me.Rows("5:169").EntireRow.Hidden = False
    ActiveWindow.ScrollRow = 4
    ActiveSheet.Range("20:169").EntireRow.Hidden = True
 Application.ScreenUpdating = True
End Sub
0
Reply Utf 6/7/2010 7:33:18 PM

I think you just answered your own question.  Unprotect the sheet, run the 
code you have, re-protect the sheet.


Sheets("Sheet1").Select
ActiveSheet.Unprotect

'your code in here    

Sheets("Sheet1").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True ' 
or whatever kind of protection you need...turn on the macro recorder and go 
through the steps...that's the easiest way...



-- 
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Ayo" wrote:

> I have the code below in a worksheet on a file in SharePoint. The worksheet 
> is Protected so only unprotected Cells are selectable. The problem I am 
> having is that when the sheet is protected I get an error on:
>          Me.Rows("5:169").EntireRow.Hidden = False
> and I know it is because on the protection because when I remove the 
> protection from the sheet, the macro works fine. Is there a way around this 
> problem?
> 
> Private Sub cmdCPA_Click()
> Application.ScreenUpdating = False
>     Me.Rows("5:169").EntireRow.Hidden = False
>     ActiveWindow.ScrollRow = 4
>     ActiveSheet.Range("20:169").EntireRow.Hidden = True
>  Application.ScreenUpdating = True
> End Sub
0
Reply Utf 6/7/2010 7:37:10 PM


Thanks.

"ryguy7272" wrote:

> I think you just answered your own question.  Unprotect the sheet, run the 
> code you have, re-protect the sheet.
> 
> 
> Sheets("Sheet1").Select
> ActiveSheet.Unprotect
> 
> 'your code in here    
> 
> Sheets("Sheet1").Select
> ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True ' 
> or whatever kind of protection you need...turn on the macro recorder and go 
> through the steps...that's the easiest way...
> 
> 
> 
> -- 
> Ryan---
> If this information was helpful, please indicate this by clicking ''Yes''.
> 
> 
> "Ayo" wrote:
> 
> > I have the code below in a worksheet on a file in SharePoint. The worksheet 
> > is Protected so only unprotected Cells are selectable. The problem I am 
> > having is that when the sheet is protected I get an error on:
> >          Me.Rows("5:169").EntireRow.Hidden = False
> > and I know it is because on the protection because when I remove the 
> > protection from the sheet, the macro works fine. Is there a way around this 
> > problem?
> > 
> > Private Sub cmdCPA_Click()
> > Application.ScreenUpdating = False
> >     Me.Rows("5:169").EntireRow.Hidden = False
> >     ActiveWindow.ScrollRow = 4
> >     ActiveSheet.Range("20:169").EntireRow.Hidden = True
> >  Application.ScreenUpdating = True
> > End Sub
0
Reply Utf 6/7/2010 8:03:14 PM

2 Replies
540 Views

(page loaded in 0.139 seconds)

Similiar Articles:













8/1/2012 10:35:45 AM


Reply: