ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Protection Macro (https://www.excelbanter.com/excel-worksheet-functions/230475-protection-macro.html)

Lois

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

macropod[_2_]

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



Lois

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





All times are GMT +1. The time now is 01:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com