protect unprotect sheet vba

I

ian bartlett

I'm hoping someone could help with this
'Sub sort()
''
'' sort Macro
'' Macro recorded 6/11/2007 by Ibartlett
'Const csPWORD As String = "CRU"
'ActiveWorkbook.Worksheets("Sorted_BedBoard_List").Unprotect
Password:=csPWORD
'
'
' Sheets("Sorted_BedBoard_List").Select
' Columns("A:G").Select
' Selection.sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes, _
' OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
' DataOption1:=xlSortNormal
' ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
' Sheets("Sheet1").Select
' Range("D5").Select
' ActiveWorkbook.Worksheets("Sorted_BedBoard_List").Protect
Password:=csPWORD
'
'End Sub

this doesn't work

this works but doesn't incorporate the sheet protection of course
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 6/12/2007 by Ibartlett
'

Application.ScreenUpdating = False

Sheets("Sorted_BedBoard_List").Select
Columns("A:G").Select
Selection.sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Sheet1").Select
Range("D5").Select
Application.ScreenUpdating = True

End Sub
Thanks for any help
Bart
 
G

Guest

Ian,

try this:-

Sub standard()
Application.ScreenUpdating = False

With Sheets("Sorted_BedBoard_List")
.Select
.Unprotect Password:="CRU"
End With
Columns("A:G").Select
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Sheet2").Select
Range("D5").Select
With Sheets("Sorted_BedBoard_List")
.Select
.Protect Password:="CRU"
End With
Application.ScreenUpdating = True

End Sub

Mike
 
G

Gary Keramidas

no need to select as far as i know

Sub Protect_All_Sheets()
Dim i As Long
For i = 1 To Worksheets.Count
With Worksheets(i)
.Protect
End With
Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top