I protect sheet - Macro will not run now

M

Marcus Analyst

I have written a Macro that automatically hides rows on a sheet upon opening
the file. When I protect the sheet, I get a run-time error 1004 "Unable to
set the hidden property of the Range Class". QUESTION: How do I get this
macro to run and protect most of the cells on the sheet? Here is the code.

Sub Auto_open()
'
' Auto_open Macro
' Hides rows 8 through 28 on "Current" worksheet
'
' Keyboard Shortcut: Ctrl+h
'
Sheets("CURRENT").Select
Rows("8:28").Select
Selection.EntireRow.Hidden = True
Sheets("Cover").Select
End Sub
 
C

C Brehm

WorkSheets("Current").unprotect "password"
and
WorkSheets("Current").protect "password"
 
G

Gord Dibben

Sub Auto_open()
'
' Auto_open Macro
' Hides rows 8 through 28 on "Current" worksheet
'
' Keyboard Shortcut: Ctrl+h
'
Sheets("CURRENT").Select
ActiveSheet.Unprotect Password:="justme"
Rows("8:28").EntireRow.Hidden = True
ActiveSheet.Protect Password:="justme"
Sheets("Cover").Select
End Sub


Gord Dibben MS Excel MVP
 
M

Marcus Analyst

Thanks Gord! I'll try this now!
--
Marc


Gord Dibben said:
Sub Auto_open()
'
' Auto_open Macro
' Hides rows 8 through 28 on "Current" worksheet
'
' Keyboard Shortcut: Ctrl+h
'
Sheets("CURRENT").Select
ActiveSheet.Unprotect Password:="justme"
Rows("8:28").EntireRow.Hidden = True
ActiveSheet.Protect Password:="justme"
Sheets("Cover").Select
End Sub


Gord Dibben MS Excel MVP
 
G

Gary Keramidas

if you use this to protect it, you won't have to worry if the sheet is protected
or not when you run your code,

Worksheets("Sheet1").Protect UserInterfaceOnly:=True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top