Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Protecting Sheet

Hi,

I have recently migrated data from one excel sheet to another. However it
is now required to protect all the migrated sheets.

I wish to do this via code rather than go into each sheet and protect.

I have opened each sheet with code and used the following code :

xl.ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True

However, i can not put the password in, this just protects the sheet with no
password, is there a way of adding the password to the code?

Thanks

Nathan.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Protecting Sheet

Try

Sub marine()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Protect Password:="MyPass", DrawingObjects:=True, Contents:=True,
Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True

Next ws
End Sub

Mike

"nathan_savidge" wrote:

Hi,

I have recently migrated data from one excel sheet to another. However it
is now required to protect all the migrated sheets.

I wish to do this via code rather than go into each sheet and protect.

I have opened each sheet with code and used the following code :

xl.ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True

However, i can not put the password in, this just protects the sheet with no
password, is there a way of adding the password to the code?

Thanks

Nathan.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Protecting Sheet

Sub ProtectAllSheets()
Application.ScreenUpdating = False
Dim n As Single
For n = 1 To Sheets.Count
Sheets(n).Protect Password:="justme", DrawingObjects:=True, _
Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True
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:="justme"
Next n
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP

On Fri, 23 May 2008 03:34:00 -0700, nathan_savidge
wrote:

Hi,

I have recently migrated data from one excel sheet to another. However it
is now required to protect all the migrated sheets.

I wish to do this via code rather than go into each sheet and protect.

I have opened each sheet with code and used the following code :

xl.ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True

However, i can not put the password in, this just protects the sheet with no
password, is there a way of adding the password to the code?

Thanks

Nathan.


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
protecting formulas without protecting sheet so grouping still wor JM Excel Discussion (Misc queries) 1 June 4th 09 06:42 AM
Protecting sheet Art Cummings Excel Discussion (Misc queries) 3 May 14th 09 09:06 PM
protecting sheet Art Cummings New Users to Excel 1 May 14th 09 06:14 PM
Protecting Sheet Nad Excel Programming 3 August 5th 06 06:30 PM
Can't use tab after protecting sheet. snam Excel Discussion (Misc queries) 3 January 21st 05 02:54 PM


All times are GMT +1. The time now is 07:35 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"