Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Problems with sheet unprotect

Hi all,

I'm having trouble with Excel sheet protection. I'm programming a macro that
will run through an Excel Workbook, searching a every sheet for certain text
and then shading the first 31 columns of the row in which the text is found.
The sheet is protected, but the code (below) tries to unprotect before it
runs. The unprotect method seems to succeed (no errors are countered), but
when it tries to change the ColorIndex property it fails as the sheet is
still protected.

In this code, each sheet is named as the date in the format "mmm yyyy", and
the code only runs on the sheet that is equal to the variable StartMonth.
I've commented in the code below where the error is encountered.

Any help would be greatly appreciated.

Thanks,
Wayne

--------------------------------------------
For C = 1 To Sheets.Count
Sheets(C).Activate
ActiveSheet.Unprotect ("PASSWORD")
For D = 1 To 74
' Only checks the first 74 rows after Range("A4")
If Range("A4").Offset(D, 0).Value = "TEXTTOCHECKFOR" Then
For E = 1 To 31
' Shade and enter 'X' in the first 31 columns
Range("A4").Offset(D, E).Interior.ColorIndex =
12632256
' THE LINE ABOVE IS WHERE IT CRASHES
Range("A4").Offset(D, E).Value = "X"
Next E
Exit For
' Stop checking for "TEXTTOCHECKFOR" once it's been found
End If
Next D
ActiveSheet.Protect ("PASSWORD")
Next C
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Problems with sheet unprotect

Hi
Your problem is not with sheet protect but the value of the ColorIndex, this
refers to the palette color which has only 56 values. Values above 56 will
throw an error.

Range("A4").Offset(D, E).Interior.ColorIndex = 5 'e.g. - set it blue


If you want to specify a specific color you could use the RGB function,
values for each color RGB can be 0 to 255 e.g.

Range("A4").Offset(D, E).Interior.Color = RGB(0, 0, 255) ' e.g. set it
blue


--
Cheers
Nigel



"Wayne" wrote in message
...
Hi all,

I'm having trouble with Excel sheet protection. I'm programming a macro

that
will run through an Excel Workbook, searching a every sheet for certain

text
and then shading the first 31 columns of the row in which the text is

found.
The sheet is protected, but the code (below) tries to unprotect before it
runs. The unprotect method seems to succeed (no errors are countered), but
when it tries to change the ColorIndex property it fails as the sheet is
still protected.

In this code, each sheet is named as the date in the format "mmm yyyy",

and
the code only runs on the sheet that is equal to the variable StartMonth.
I've commented in the code below where the error is encountered.

Any help would be greatly appreciated.

Thanks,
Wayne

--------------------------------------------
For C = 1 To Sheets.Count
Sheets(C).Activate
ActiveSheet.Unprotect ("PASSWORD")
For D = 1 To 74
' Only checks the first 74 rows after Range("A4")
If Range("A4").Offset(D, 0).Value = "TEXTTOCHECKFOR" Then
For E = 1 To 31
' Shade and enter 'X' in the first 31 columns
Range("A4").Offset(D, E).Interior.ColorIndex =
12632256
' THE LINE ABOVE IS WHERE IT CRASHES
Range("A4").Offset(D, E).Value = "X"
Next E
Exit For
' Stop checking for "TEXTTOCHECKFOR" once it's been

found
End If
Next D
ActiveSheet.Protect ("PASSWORD")
Next C



Reply
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
I need to unprotect sheet so I cn sve it but need a password? scout ron Excel Discussion (Misc queries) 2 May 28th 10 03:05 PM
unprotect sheet macro belvy123 Excel Discussion (Misc queries) 2 March 27th 08 10:36 PM
how to Unprotect sheet mangesh Excel Discussion (Misc queries) 1 July 24th 06 10:34 PM
Excel VBA - Problems using Protect/Unprotect a worksheet Gary Richie Excel Programming 2 February 6th 04 03:29 AM
unprotect sheet in code and make sheet visible peach255 Excel Programming 1 August 1st 03 03:28 AM


All times are GMT +1. The time now is 04:21 PM.

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"