Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
tek tek is offline
external usenet poster
 
Posts: 10
Default Protect/Unprotect Multiple Sheets With Full Options

I currently have a macro which allows me to protect/unprotect multiple
wortksheets. However, how do I expand the code to apply all the protection
options when protecting? I keep receiving errors when manipulating the code
after referencing it from the macro recorder. My current code is as follows:


Sub ProtectAllSheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Protect Password:="password"
Next N
Application.ScreenUpdating = True
End Sub

Sub UnprotectAllSheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Unprotect Password:="password"
Next N
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Protect/Unprotect Multiple Sheets With Full Options

Record a macro when you manually protect a worksheet with the options you want.

Then try to incorporate that into your code.

If you have trouble, post that code and indicate the line that's causing the
trouble.

TEK wrote:

I currently have a macro which allows me to protect/unprotect multiple
wortksheets. However, how do I expand the code to apply all the protection
options when protecting? I keep receiving errors when manipulating the code
after referencing it from the macro recorder. My current code is as follows:


Sub ProtectAllSheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Protect Password:="password"
Next N
Application.ScreenUpdating = True
End Sub

Sub UnprotectAllSheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Unprotect Password:="password"
Next N
Application.ScreenUpdating = True
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
tek tek is offline
external usenet poster
 
Posts: 10
Default Protect/Unprotect Multiple Sheets With Full Options

Hi Dave,

When I add the below, which is all the protection options checked, I receive
a "object required" error. I changed "Active" sheet to "Any".

AnySheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True,
AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True

"Dave Peterson" wrote:

Record a macro when you manually protect a worksheet with the options you want.

Then try to incorporate that into your code.

If you have trouble, post that code and indicate the line that's causing the
trouble.

TEK wrote:

I currently have a macro which allows me to protect/unprotect multiple
wortksheets. However, how do I expand the code to apply all the protection
options when protecting? I keep receiving errors when manipulating the code
after referencing it from the macro recorder. My current code is as follows:


Sub ProtectAllSheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Protect Password:="password"
Next N
Application.ScreenUpdating = True
End Sub

Sub UnprotectAllSheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Unprotect Password:="password"
Next N
Application.ScreenUpdating = True
End Sub


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Protect/Unprotect Multiple Sheets With Full Options

You'd want to use Sheets(N):

Option Explicit
Sub ProtectAllSheets()
Application.ScreenUpdating = False
Dim N As Long
For N = 1 To Sheets.Count
Sheets(N).Protect _
Password:="password", _
DrawingObjects:=False, _
Contents:=True, _
Scenarios:=False, _
AllowFormattingCells:=True, _
AllowFormattingColumns:=True, _
AllowFormattingRows:=True, _
AllowInsertingColumns:=True, _
AllowInsertingRows:=True, _
AllowInsertingHyperlinks:=True, _
AllowDeletingColumns:=True, _
AllowDeletingRows:=True, _
AllowSorting:=True, _
AllowFiltering:=True, _
AllowUsingPivotTables:=True
Next N
Application.ScreenUpdating = True
End Sub



TEK wrote:

Hi Dave,

When I add the below, which is all the protection options checked, I receive
a "object required" error. I changed "Active" sheet to "Any".

AnySheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True,
AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True

"Dave Peterson" wrote:

Record a macro when you manually protect a worksheet with the options you want.

Then try to incorporate that into your code.

If you have trouble, post that code and indicate the line that's causing the
trouble.

TEK wrote:

I currently have a macro which allows me to protect/unprotect multiple
wortksheets. However, how do I expand the code to apply all the protection
options when protecting? I keep receiving errors when manipulating the code
after referencing it from the macro recorder. My current code is as follows:


Sub ProtectAllSheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Protect Password:="password"
Next N
Application.ScreenUpdating = True
End Sub

Sub UnprotectAllSheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Unprotect Password:="password"
Next N
Application.ScreenUpdating = True
End Sub


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
tek tek is offline
external usenet poster
 
Posts: 10
Default Protect/Unprotect Multiple Sheets With Full Options

Dave,

This worked perfectly! Thanks for your help, it's much appreciated.


"Dave Peterson" wrote:

You'd want to use Sheets(N):

Option Explicit
Sub ProtectAllSheets()
Application.ScreenUpdating = False
Dim N As Long
For N = 1 To Sheets.Count
Sheets(N).Protect _
Password:="password", _
DrawingObjects:=False, _
Contents:=True, _
Scenarios:=False, _
AllowFormattingCells:=True, _
AllowFormattingColumns:=True, _
AllowFormattingRows:=True, _
AllowInsertingColumns:=True, _
AllowInsertingRows:=True, _
AllowInsertingHyperlinks:=True, _
AllowDeletingColumns:=True, _
AllowDeletingRows:=True, _
AllowSorting:=True, _
AllowFiltering:=True, _
AllowUsingPivotTables:=True
Next N
Application.ScreenUpdating = True
End Sub



TEK wrote:

Hi Dave,

When I add the below, which is all the protection options checked, I receive
a "object required" error. I changed "Active" sheet to "Any".

AnySheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True,
AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True

"Dave Peterson" wrote:

Record a macro when you manually protect a worksheet with the options you want.

Then try to incorporate that into your code.

If you have trouble, post that code and indicate the line that's causing the
trouble.

TEK wrote:

I currently have a macro which allows me to protect/unprotect multiple
wortksheets. However, how do I expand the code to apply all the protection
options when protecting? I keep receiving errors when manipulating the code
after referencing it from the macro recorder. My current code is as follows:


Sub ProtectAllSheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Protect Password:="password"
Next N
Application.ScreenUpdating = True
End Sub

Sub UnprotectAllSheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Unprotect Password:="password"
Next N
Application.ScreenUpdating = True
End Sub

--

Dave Peterson


--

Dave Peterson



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
Protect/unprotect all sheets at once? wx4usa New Users to Excel 4 July 22nd 08 12:08 AM
Protect-Unprotect all the sheets Gary Excel Worksheet Functions 7 February 26th 07 08:13 PM
How to protect and unprotect multiple worksheets effeciently Sumknight Excel Discussion (Misc queries) 4 February 23rd 07 08:10 PM
Protect/Unprotect Multiple Worksheets Katherine R Excel Discussion (Misc queries) 2 May 9th 06 04:07 PM
Macros for Protect/Unprotect all sheets in a workbook Paul Sheppard Excel Discussion (Misc queries) 2 August 4th 05 04:30 PM


All times are GMT +1. The time now is 12:43 PM.

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"