View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
StargateFan[_3_] StargateFan[_3_] is offline
external usenet poster
 
Posts: 171
Default Vital: Protecting sheets so macros/buttons still work?

On Sat, 3 Jul 2004 18:58:57 +0800, "JulieD"
wrote:

Hi

you can use
ActiveSheet.Protect
and
ActiveSheet.Unprotect
which will protect (unprotect) the currently active sheet without having to
specify the sheet name

which i think is what you're after.

Regards
JulieD


Thank you!

"StargateFanFromWork" wrote in message
...
"Marcotte A" wrote in message
...

[snip]

This can be handled as suggested:
Sub YourMacro()
ThisWorkbook.Worksheets("Sheet1).Unprotect("YourPa ssword")
'your code
ThisWorkbook.Worksheets("Sheet1).Protect("YourPass word")
End Sub

If you have the workbook protected instead then:
ThisWorkbook.Protect etc.


I knew it. This isn't working. I get a runtime error of 9, this time
around, "Subscript out of range".

Here's the coding, fiddle with many times:


ThisWorkbook.Worksheets("").Unprotect ("")
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,

Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
ThisWorkbook.Worksheets("").Protect ("")


Why did I change it from the above? Because I'm hoping that I can just
copy/paste the code into the 20 other sort macros in all the workbooks

I've
created. Also, it'll make portability much more feasible. I'll probably

be
re-using this code, again and again. I'd like to leave the worksheet name
out of things always and I never use passwords. I'm a contract worker and

I
need to know that they can go in and modify anything if they need to down
the road after I'm gone.

I tried numerous variations on the above Unprotect and Protect syntax but
often got the red right away.

Is there a command builder in Excel that can help? One that can give

better
and more precise help than trying to do a google search. Googling gives

no
results anyway, btw (I've tried in the past). There's got to be a way for

us
to much more easily look up code to do something and to get the variations
in the syntax right very quickly. That would save all of us because I
wouldn't pester the groups so much! <lol

Anyway, that would be appreciated but also, a more generic code that works
for the above <sigh. This is the only issue standing in the way of
protecting and locking up all these sheets.

Thanks so much! I really appreciate all the help!