excel - Protect worksheet not workbook -


i have excel spreadsheet needs of it's cells protected editing. can't protect sheet in usual way because work groups (little + @ top expand columns).

i found vba macro protect sheet, noticed in excel 2010 "unprotect sheet" , modify everything, though whole workbook still protected.

this macro use @ "thisworkbook":

private sub worksheet_change(byval target range) activesheet.unprotect password:="nopassword"  if range("c3").value = "protect"      range("c4:c65536").locked = true  else     range("c4:c65536").locked = false end if activesheet.protect password:="fakepass"  end sub  private sub workbook_open() dim x long  x = 1 activeworkbook.sheets.count     activeworkbook.sheets(x)         .protect userinterfaceonly:=true         .enableoutlining = true     end next  end sub 

how can modify code work sheet 1?

i'm aware it's not safest form of protection it's merely prevent people modifying cells accidentally.

if change:

activesheet.protect password:="fakepass"  

to:

worksheets("sheet1").protect password:="fakepass" 

it apply sheet1 rather active sheet only.

or create macro protect sheets, like:

sub protectall()  dim ws worksheet  each ws in activeworkbook.worksheets ws.protect password:="fakepass", drawingobjects:=true, contents:=true, scenarios:=true next ws  end sub 

and call main code?


Comments