Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Protect ALL sheets in one coded macro

How can i word a code to protect ALL sheets in a workbook in a single step,
rather than individually?

Sub protect()
' Macro recorded 24-11-2006 by Corey
'
ThisWorkbook.Worksheets("Sheet 10").protect Password:="1234" ' <=== Some
thing like this workbook.worksheets(all).protect password:="1234"
ActiveSheet.protect
End Sub


How can i write this?

Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default Protect ALL sheets in one coded macro

Corey,

Sub Protect_All_Sheets()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets

ws.Protect password:="1234"

Next ws

End Sub
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003


"Corey" wrote in message
...
How can i word a code to protect ALL sheets in a workbook in a single
step, rather than individually?

Sub protect()
' Macro recorded 24-11-2006 by Corey
'
ThisWorkbook.Worksheets("Sheet 10").protect Password:="1234" ' <=== Some
thing like this workbook.worksheets(all).protect password:="1234"
ActiveSheet.protect
End Sub


How can i write this?

Corey....



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Protect ALL sheets in one coded macro

thanks Paul.

I have placed a command button on sheet1 to call the code you posted, but it
seem to ONLY apply to the sheet1.
Although the code refers to all sheets?
Why would this be?
Corey....
"Paul B" wrote in message
...
Corey,

Sub Protect_All_Sheets()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets

ws.Protect password:="1234"

Next ws

End Sub
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003


"Corey" wrote in message
...
How can i word a code to protect ALL sheets in a workbook in a single
step, rather than individually?

Sub protect()
' Macro recorded 24-11-2006 by Corey
'
ThisWorkbook.Worksheets("Sheet 10").protect Password:="1234" ' <=== Some
thing like this workbook.worksheets(all).protect password:="1234"
ActiveSheet.protect
End Sub


How can i write this?

Corey....





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Protect ALL sheets in one coded macro

never mind.
worked it out.
Had cells selected as locked cells can be selected in some sheets.

Corey....
"Corey" wrote in message
...
thanks Paul.

I have placed a command button on sheet1 to call the code you posted, but
it seem to ONLY apply to the sheet1.
Although the code refers to all sheets?
Why would this be?
Corey....
"Paul B" wrote in message
...
Corey,

Sub Protect_All_Sheets()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets

ws.Protect password:="1234"

Next ws

End Sub
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003


"Corey" wrote in message
...
How can i word a code to protect ALL sheets in a workbook in a single
step, rather than individually?

Sub protect()
' Macro recorded 24-11-2006 by Corey
'
ThisWorkbook.Worksheets("Sheet 10").protect Password:="1234" ' <=== Some
thing like this workbook.worksheets(all).protect password:="1234"
ActiveSheet.protect
End Sub


How can i write this?

Corey....







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Protect ALL sheets in one coded macro

Give these a try...

Sub ProtectAll
dim wks as worksheet

for each wks in worksheets
wks.protect Password:="1234"
next wks
end sub

Sub UnProtectAll
dim wks as worksheet

for each wks in worksheets
wks.unprotect Password:="1234"
next wks
end sub
--
HTH...

Jim Thomlinson


"Corey" wrote:

How can i word a code to protect ALL sheets in a workbook in a single step,
rather than individually?

Sub protect()
' Macro recorded 24-11-2006 by Corey
'
ThisWorkbook.Worksheets("Sheet 10").protect Password:="1234" ' <=== Some
thing like this workbook.worksheets(all).protect password:="1234"
ActiveSheet.protect
End Sub


How can i write this?

Corey....





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default Protect ALL sheets in one coded macro

I have not tried this but it might work:

Sheets(Array("Sheet1","Sheet2", name each sheet in this manner)).protect
Password:="1234"

Else

x=1
for each sheet in workbooks
if x sheets.count then exit for
end if
Sheets(x).protect Password:="1234"
next x

--
Best wishes,

Jim


"Corey" wrote:

How can i word a code to protect ALL sheets in a workbook in a single step,
rather than individually?

Sub protect()
' Macro recorded 24-11-2006 by Corey
'
ThisWorkbook.Worksheets("Sheet 10").protect Password:="1234" ' <=== Some
thing like this workbook.worksheets(all).protect password:="1234"
ActiveSheet.protect
End Sub


How can i write this?

Corey....



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
Macro to Protect Mult Sheets / but allow Pivot Tables... Chris Excel Worksheet Functions 0 November 13th 08 06:37 PM
Macro to protect multiple sheets? Stilla Excel Worksheet Functions 12 March 5th 07 07:03 PM
Use Macro to protect choosen sheets in workbook kevhatch Excel Discussion (Misc queries) 1 January 27th 07 06:52 PM
Macro - settings to protect sheets Philipp Eckardt Excel Programming 1 October 30th 06 02:49 AM
Protect sheets from editing but allowing macro to do so? NooK[_52_] Excel Programming 5 August 5th 04 03:55 PM


All times are GMT +1. The time now is 09:36 AM.

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

About Us

"It's about Microsoft Excel"