View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
ernestgoh[_7_] ernestgoh[_7_] is offline
external usenet poster
 
Posts: 1
Default VBA password protect


brian thompson3001 via OfficeKB.com Wrote:
Hi

I have got this macro to run when opening. All works, but when I
password
protect the sheet, and then close and open i get a run error.

I am not fluent with VBA and get by by recording and pasting other work
off
the treads

Can anyone let me have the VBA code for protect / unprotect. and where
it
should be entered in the code below . The password is "template"

thanks in advance

Private Sub auto_Open()
Sub averagesort()
Range("A6:AI36").Select
Selection.Sort Key1:=Range("C6"), Order1:=xlDescending,
Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlBottomToTop
ActiveWindow.ScrollRow = 6
Range("A3").Select
End Sub

--
bnt

Message posted via http://www.officekb.com


hi brian,

you may use this :

Private Sub auto_Open()

Worksheets("-Name of your worksheet-").unprotect password:="template"

Sub averagesort()
Range("A6:AI36").Select
Selection.Sort Key1:=Range("C6"), Order1:=xlDescending,
Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlBottomToTop
ActiveWindow.ScrollRow = 6
Range("A3").Select

Worksheets("-Name of your worksheet-").protect password:="template"

End Sub

best regards, ernest goh


--
ernestgoh
------------------------------------------------------------------------
ernestgoh's Profile: http://www.excelforum.com/member.php...o&userid=24870
View this thread: http://www.excelforum.com/showthread...hreadid=561857