#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 42
Default Protection Macro

Hi,
I have the following macro written in spreadsheets to protect them, however,
in some workbooks there are 12 month tabs & a 'workings' tab. in the
workings tab i require different functionality (e.g. inserting rows &
columns) than the 12 month tabs. How do i change the macro to reflect this?

Sub ProtectAll()
Dim sPassword As String
sPassword = "LMW5487"
If Application.InputBox( _
Prompt:="Please enter the password", _
Title:="Password", _
Type:=2) < sPassword Then
MsgBox "Wrong password!"
Exit Sub
End If
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Protect Password:="LMW5487", DrawingObjects:=False, Contents:=True,
Scenarios:= _
True, AllowFormattingCells:=True, AllowSorting:=True,
AllowDeletingRows:=True, AllowInsertingRows:=True, AllowFormattingRows:=True,
AllowFiltering:= _
True, AllowFormattingColumns:=True
Next ws
End Sub

--
Lois
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 293
Default Protection Macro

Hi Lois,

According to your code, inserting & deleting rows is already allowed. Presumably you want the 'workings' sheet to allow inserting &
deleting columns also. In that case:

Sub ProtectAll()
Dim sPassword As String
sPassword = "LMW5487"
If Application.InputBox(Prompt:="Please enter the password", Title:="Password", _
Type:=2) < sPassword Then
MsgBox "Wrong password!"
End
End If
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Name < "workings" Then
ws.Protect Password:="sPassword", DrawingObjects:=False, Contents:=True, _
Scenarios:=True, AllowFormattingCells:=True, AllowSorting:=True, _
AllowDeletingRows:=True, AllowInsertingRows:=True, AllowFormattingRows:=True, _
AllowFiltering:=True, AllowFormattingColumns:=True
Else
ws.Protect Password:="sPassword", DrawingObjects:=False, Contents:=True, _
Scenarios:=True, AllowFormattingCells:=True, AllowSorting:=True, _
AllowDeletingRows:=True, AllowInsertingRows:=True, AllowFormattingRows:=True, _
AllowFiltering:=True, AllowFormattingColumns:=True, AllowInsertingColumns:=True, _
AllowDeletingColumns:=True
End If
Next ws
End Sub

where 'workings' is the name of the worksheet to leave unprotected

--
Cheers
macropod
[Microsoft MVP - Word]


"Lois" wrote in message ...
Hi,
I have the following macro written in spreadsheets to protect them, however,
in some workbooks there are 12 month tabs & a 'workings' tab. in the
workings tab i require different functionality (e.g. inserting rows &
columns) than the 12 month tabs. How do i change the macro to reflect this?

Sub ProtectAll()
Dim sPassword As String
sPassword = "LMW5487"
If Application.InputBox( _
Prompt:="Please enter the password", _
Title:="Password", _
Type:=2) < sPassword Then
MsgBox "Wrong password!"
Exit Sub
End If
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Protect Password:="LMW5487", DrawingObjects:=False, Contents:=True,
Scenarios:= _
True, AllowFormattingCells:=True, AllowSorting:=True,
AllowDeletingRows:=True, AllowInsertingRows:=True, AllowFormattingRows:=True,
AllowFiltering:= _
True, AllowFormattingColumns:=True
Next ws
End Sub

--
Lois


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 42
Default Protection Macro

great thanks
--
Lois


"macropod" wrote:

Hi Lois,

According to your code, inserting & deleting rows is already allowed. Presumably you want the 'workings' sheet to allow inserting &
deleting columns also. In that case:

Sub ProtectAll()
Dim sPassword As String
sPassword = "LMW5487"
If Application.InputBox(Prompt:="Please enter the password", Title:="Password", _
Type:=2) < sPassword Then
MsgBox "Wrong password!"
End
End If
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Name < "workings" Then
ws.Protect Password:="sPassword", DrawingObjects:=False, Contents:=True, _
Scenarios:=True, AllowFormattingCells:=True, AllowSorting:=True, _
AllowDeletingRows:=True, AllowInsertingRows:=True, AllowFormattingRows:=True, _
AllowFiltering:=True, AllowFormattingColumns:=True
Else
ws.Protect Password:="sPassword", DrawingObjects:=False, Contents:=True, _
Scenarios:=True, AllowFormattingCells:=True, AllowSorting:=True, _
AllowDeletingRows:=True, AllowInsertingRows:=True, AllowFormattingRows:=True, _
AllowFiltering:=True, AllowFormattingColumns:=True, AllowInsertingColumns:=True, _
AllowDeletingColumns:=True
End If
Next ws
End Sub

where 'workings' is the name of the worksheet to leave unprotected

--
Cheers
macropod
[Microsoft MVP - Word]


"Lois" wrote in message ...
Hi,
I have the following macro written in spreadsheets to protect them, however,
in some workbooks there are 12 month tabs & a 'workings' tab. in the
workings tab i require different functionality (e.g. inserting rows &
columns) than the 12 month tabs. How do i change the macro to reflect this?

Sub ProtectAll()
Dim sPassword As String
sPassword = "LMW5487"
If Application.InputBox( _
Prompt:="Please enter the password", _
Title:="Password", _
Type:=2) < sPassword Then
MsgBox "Wrong password!"
Exit Sub
End If
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Protect Password:="LMW5487", DrawingObjects:=False, Contents:=True,
Scenarios:= _
True, AllowFormattingCells:=True, AllowSorting:=True,
AllowDeletingRows:=True, AllowInsertingRows:=True, AllowFormattingRows:=True,
AllowFiltering:= _
True, AllowFormattingColumns:=True
Next ws
End Sub

--
Lois



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 protection Lois Excel Worksheet Functions 3 May 8th 09 09:34 AM
macro protection albertmb Excel Discussion (Misc queries) 4 January 1st 09 10:37 AM
Protection macro Neil Pearce Excel Discussion (Misc queries) 4 October 24th 08 09:56 AM
Macro and row protection RoyG Excel Discussion (Misc queries) 1 February 19th 08 12:05 AM
macro for protection ynissel Excel Discussion (Misc queries) 3 August 3rd 05 09:52 PM


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