Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default VBA password protect

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default VBA password protect

if you are using the active sheet and not using a password, use
ActiveSheet.Protect
ActiveSheet.Unprotect

If you are using a password,
ActiveSheet.Protect password:="whatever"
ActiveSheet.Unprotect password:="whatever"
James

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default VBA password protect

Hi Ernest

tried you alteration and the macro would not run. I copied and pasted into
"View Code" (right click on tab)

worksheet name "WTD"
Password "template"

any ideas why?


regards

ernestgoh wrote:
brian thompson3001 via OfficeKB.com Wrote:
Hi

[quoted text clipped - 25 lines]
--
bnt


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


--
bnt

Message posted via http://www.officekb.com
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA password protect


Hi Brian

Try this as an example. Name one of your worksheet as "WTD". I teste
it out and it worked so you shouldn't have any problems.

Private Sub auto_Open()

Worksheets("WTD").Unprotect password:="template"

Sub averagesort()
Range("A6:AI36").Select
ActiveWindow.ScrollRow = 6
Range("A3").Select

Worksheets("WTD").Protect password:="template"

End Sub

Best regards, Ernest Goh

brian thompson3001 via OfficeKB.com Wrote:
Hi Ernest

tried you alteration and the macro would not run. I copied and paste
into
"View Code" (right click on tab)

worksheet name "WTD"
Password "template"

any ideas why?


regards

ernestgoh wrote:
brian thompson3001 via OfficeKB.com Wrote:
Hi

d text clipped - 25 lines Wrote:


--
bnt

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


--
bnt

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


--
ernestgo
-----------------------------------------------------------------------
ernestgoh's Profile: http://www.excelforum.com/member.php...fo&userid=2487
View this thread: http://www.excelforum.com/showthread.php?threadid=56185

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Protect Kelly Excel Discussion (Misc queries) 2 January 18th 07 09:52 PM
VBA password protect brian thompson3001 via OfficeKB.com New Users to Excel 1 July 16th 06 07:23 PM
Password Protect cubsfan Excel Discussion (Misc queries) 0 April 7th 06 03:34 PM
protect with password nowfal[_8_] Excel Programming 6 July 16th 05 08:46 PM
Password protect crapit Excel Programming 2 June 13th 04 01:15 PM


All times are GMT +1. The time now is 04:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"