View Single Post
  #6   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 Wed, 30 Jun 2004 16:19:34 -0400, "StargateFanFromWork"
wrote:

"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.


[snip]

Phew, okay, I'm feeling a little shaky, so if I may, I'm copying the above
macro with close to what I believe unprotect/protect code might be? p.s.,
to reiterate, I don't use passwords, it's not necessary; and, secondly, can
a "generic" worksheet name be used somehow? I have over a dozen sheets in
various workbooks to add the unprotect/protect code and it would be so much
easier to not have to name the sheets. This way, it'll be much easier to
quickly secure these documents from accidental modification of the layouts
and buttons.


[snip]

I'm not sure of syntax, so re-postiong.

Sub SortByFILENAME()
'
' Macro recorded 6/25/2004 by ...
'

'
ThisWorkbook.Worksheets().Unprotect()
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
ThisWorkbook.Worksheets().Protect()
End Sub

************
I don't use passwords so the part where one enters a password, is that
code necessary? Also, all the sheets, as I mentioned above, have
different tab names. Is there a "generic" type of code for the sheet
name that will work?

Thanks.