Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Protect_Unprotect Macro modification.


Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)


'
End Sub


it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?


Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Protect_Unprotect Macro modification.

I think that the safest thing to try is to record a macro when you protect a
worksheet and toggle the settings that you want checked.

You'll see the code you need to add to your code.

If you have trouble incorporating the changes, post the recorded macro code and
I'm sure you'll get help.

Colin Hayes wrote:

Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?

Thanks.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Protect_Unprotect Macro modification.


Hi Dave

Thanks for getting back to me on this. I'm grateful for your advice ,
and did think that what you suggest was in fact exactly what I'm doing.
I'm posting my existing code , with the additional code I need to
incorporate and asking if anyone with greater expertise can help marry
the two.

My existing code actually undoes the toggled settings. I have the code
to produce the settings I need , I just don't know how to put them into
my macro so that the settings remain in place when I run it.

Sorry if I wasn't clear before.

^_^





In article , Dave Peterson
writes
I think that the safest thing to try is to record a macro when you protect a
worksheet and toggle the settings that you want checked.

You'll see the code you need to add to your code.

If you have trouble incorporating the changes, post the recorded macro code and
I'm sure you'll get help.

Colin Hayes wrote:

Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?

Thanks.




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Protect_Unprotect Macro modification.

I'm not sure which ones you want turned back on:

wkSht.Protect Password:=PWORD

Wksht.Protect password:=PWORD DrawingObjects:=False, Contents:=True, _
Scenarios:= True, AllowFormattingColumns:=True, _
AllowInsertingColumns:=True, AllowInsertingRows:=True, _
AllowDeletingRows:=True, AllowFiltering:=True, AllowFormattingRows:=True

I just chose those at random.



Colin Hayes wrote:

Hi Dave

Thanks for getting back to me on this. I'm grateful for your advice ,
and did think that what you suggest was in fact exactly what I'm doing.
I'm posting my existing code , with the additional code I need to
incorporate and asking if anyone with greater expertise can help marry
the two.

My existing code actually undoes the toggled settings. I have the code
to produce the settings I need , I just don't know how to put them into
my macro so that the settings remain in place when I run it.

Sorry if I wasn't clear before.

^_^

In article , Dave Peterson
writes
I think that the safest thing to try is to record a macro when you protect a
worksheet and toggle the settings that you want checked.

You'll see the code you need to add to your code.

If you have trouble incorporating the changes, post the recorded macro code and
I'm sure you'll get help.

Colin Hayes wrote:

Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?

Thanks.



--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Protect_Unprotect Macro modification.

Colin

Your code toggles protection on/off each sheet so you will have various states
of protection unless you set all sheets first to protected or unprotected.

Is this what you want? Or do you want to protect or unprotect all sheets
together?

The AllowFormattingRows and a couple of other modes have been added below.

Also, CTRL + z is the default Excel UnDo shortcut key. You may want to try
another combo.

Sub Protect_Unprotect()
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD, DrawingObjects:=True, _
Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

End Sub


Gord Dibben MS Excel MVP

On Mon, 21 May 2007 02:45:22 +0100, Colin Hayes
wrote:


Hi Dave

Thanks for getting back to me on this. I'm grateful for your advice ,
and did think that what you suggest was in fact exactly what I'm doing.
I'm posting my existing code , with the additional code I need to
incorporate and asking if anyone with greater expertise can help marry
the two.

My existing code actually undoes the toggled settings. I have the code
to produce the settings I need , I just don't know how to put them into
my macro so that the settings remain in place when I run it.

Sorry if I wasn't clear before.

^_^





In article , Dave Peterson
writes
I think that the safest thing to try is to record a macro when you protect a
worksheet and toggle the settings that you want checked.

You'll see the code you need to add to your code.

If you have trouble incorporating the changes, post the recorded macro code and
I'm sure you'll get help.

Colin Hayes wrote:

Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?

Thanks.






  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Protect_Unprotect Macro modification.


Hi Gord

Thanks for your help. Still no joy I'm afraid.

I have a workbook of 25 sheets , and I use the macro to unprotect /
protect them all at one go. They are all either protect or unprotected
together and the macro toggles them.

I want to have row formatting available at all times , whether the sheet
is protected of unprotected. I need to be able to hide / unhide rows at
all times.

I find that if I set this manually for a sheet then it works , and
allows me to format rows in protected and unprotected state. The row
formatting commands are available. This is how I want it.

However , after I run the macro below , the ability to format rows is
gone. The row formatting commands are greyed out.

I just need the macro to be amended so it won't overwrite the row
formatting permission. I did try your amendment below , but couldn't
make it work.

So , that's it. Hope you can help.

Thanks.


In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
Colin

Your code toggles protection on/off each sheet so you will have various states
of protection unless you set all sheets first to protected or unprotected.

Is this what you want? Or do you want to protect or unprotect all sheets
together?

The AllowFormattingRows and a couple of other modes have been added below.

Also, CTRL + z is the default Excel UnDo shortcut key. You may want to try
another combo.

Sub Protect_Unprotect()
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD, DrawingObjects:=True, _
Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

End Sub


Gord Dibben MS Excel MVP

On Mon, 21 May 2007 02:45:22 +0100, Colin Hayes

wrote:


Hi Dave

Thanks for getting back to me on this. I'm grateful for your advice ,
and did think that what you suggest was in fact exactly what I'm doing.
I'm posting my existing code , with the additional code I need to
incorporate and asking if anyone with greater expertise can help marry
the two.

My existing code actually undoes the toggled settings. I have the code
to produce the settings I need , I just don't know how to put them into
my macro so that the settings remain in place when I run it.

Sorry if I wasn't clear before.

^_^





In article , Dave Peterson
writes
I think that the safest thing to try is to record a macro when you protect a
worksheet and toggle the settings that you want checked.

You'll see the code you need to add to your code.

If you have trouble incorporating the changes, post the recorded macro code and
I'm sure you'll get help.

Colin Hayes wrote:

Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?

Thanks.




  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Protect_Unprotect Macro modification.

In article , Dave Peterson
writes
I'm not sure which ones you want turned back on:

wkSht.Protect Password:=PWORD

Wksht.Protect password:=PWORD DrawingObjects:=False, Contents:=True, _
Scenarios:= True, AllowFormattingColumns:=True, _
AllowInsertingColumns:=True, AllowInsertingRows:=True, _
AllowDeletingRows:=True, AllowFiltering:=True, AllowFormattingRows:=True

I just chose those at random.



Hi Dave

Ok Thanks. I'm not sure where to place this in the macro - I'm getting
red errors when I try to paste it in. If you could advise on that I'd be
grateful.

It's just row formatting i need switched on.

Thanks



Colin Hayes wrote:

Hi Dave

Thanks for getting back to me on this. I'm grateful for your advice ,
and did think that what you suggest was in fact exactly what I'm doing.
I'm posting my existing code , with the additional code I need to
incorporate and asking if anyone with greater expertise can help marry
the two.

My existing code actually undoes the toggled settings. I have the code
to produce the settings I need , I just don't know how to put them into
my macro so that the settings remain in place when I run it.

Sorry if I wasn't clear before.

^_^

In article , Dave Peterson
writes
I think that the safest thing to try is to record a macro when you protect a
worksheet and toggle the settings that you want checked.

You'll see the code you need to add to your code.

If you have trouble incorporating the changes, post the recorded macro code

and
I'm sure you'll get help.

Colin Hayes wrote:

Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?

Thanks.





Are you aware that we also buy CDs, Vinyl and DVDs? Send your lists of
unwanted items to and well quote you a price€¦


You can browse and buy direct from my full list of items at these addresses :

http://s1.amazon.co.uk/exec/varzea/t.../026-3393902-9
050050

or:

http://www.CDandVinyl.co.uk

or :

http://www.netsoundsmusic.com/chayes

or:

http://chayes.musicstack.com



To DOWNLOAD the full catalogue click here :


http://www.chayes.demon.co.uk/CDandV..._catalogue.exe



Best Wishes ,

Colin Hayes.



TEL / FAX : (UK) (0)208 804 9181
  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Protect_Unprotect Macro modification.

Replace this line:
wkSht.Protect Password:=PWORD
with
wkSht.Protect Password:=PWORD, AllowFormattingRows:=True

Colin Hayes wrote:

In article , Dave Peterson
writes
I'm not sure which ones you want turned back on:

wkSht.Protect Password:=PWORD

Wksht.Protect password:=PWORD DrawingObjects:=False, Contents:=True, _
Scenarios:= True, AllowFormattingColumns:=True, _
AllowInsertingColumns:=True, AllowInsertingRows:=True, _
AllowDeletingRows:=True, AllowFiltering:=True, AllowFormattingRows:=True

I just chose those at random.



Hi Dave

Ok Thanks. I'm not sure where to place this in the macro - I'm getting
red errors when I try to paste it in. If you could advise on that I'd be
grateful.

It's just row formatting i need switched on.

Thanks


Colin Hayes wrote:

Hi Dave

Thanks for getting back to me on this. I'm grateful for your advice ,
and did think that what you suggest was in fact exactly what I'm doing.
I'm posting my existing code , with the additional code I need to
incorporate and asking if anyone with greater expertise can help marry
the two.

My existing code actually undoes the toggled settings. I have the code
to produce the settings I need , I just don't know how to put them into
my macro so that the settings remain in place when I run it.

Sorry if I wasn't clear before.

^_^

In article , Dave Peterson
writes
I think that the safest thing to try is to record a macro when you protect a
worksheet and toggle the settings that you want checked.

You'll see the code you need to add to your code.

If you have trouble incorporating the changes, post the recorded macro code

and
I'm sure you'll get help.

Colin Hayes wrote:

Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?

Thanks.



Are you aware that we also buy CDs, Vinyl and DVDs? Send your lists of
unwanted items to and well quote you a price€¦

You can browse and buy direct from my full list of items at these addresses :

http://s1.amazon.co.uk/exec/varzea/t.../026-3393902-9
050050

or:

http://www.CDandVinyl.co.uk

or :

http://www.netsoundsmusic.com/chayes

or:

http://chayes.musicstack.com

To DOWNLOAD the full catalogue click here :

http://www.chayes.demon.co.uk/CDandV..._catalogue.exe

Best Wishes ,

Colin Hayes.

TEL / FAX : (UK) (0)208 804 9181


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Protect_Unprotect Macro modification.

In article , Dave Peterson
writes
Replace this line:
wkSht.Protect Password:=PWORD
with
wkSht.Protect Password:=PWORD, AllowFormattingRows:=True


Hi Dave

Thanks for getting back. Still no joy , I'm afraid.

I'm highlighting all the rows on the sheet. I run the macro to unprotect
the sheet , and right click. The Hide and Unhide switches in the popup
are activated and in black.

I run the macro to protect the sheet again. Now when I right click the
Hide and unhide switched are greyed out. I need these to be accessible
when the sheet is protected , and would have thought that your
suggestion would have worked.

hmmm - bit stuck now.


This is how it is with your line in place :

' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD, AllowFormattingRows:=True
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)


'
End Sub


I can't see why this wouldn't work.

Thanks again.



Colin Hayes wrote:

In article , Dave Peterson
writes
I'm not sure which ones you want turned back on:

wkSht.Protect Password:=PWORD

Wksht.Protect password:=PWORD DrawingObjects:=False, Contents:=True, _
Scenarios:= True, AllowFormattingColumns:=True, _
AllowInsertingColumns:=True, AllowInsertingRows:=True, _
AllowDeletingRows:=True, AllowFiltering:=True, AllowFormattingRows:=True

I just chose those at random.



Hi Dave

Ok Thanks. I'm not sure where to place this in the macro - I'm getting
red errors when I try to paste it in. If you could advise on that I'd be
grateful.

It's just row formatting i need switched on.

Thanks


Colin Hayes wrote:

Hi Dave

Thanks for getting back to me on this. I'm grateful for your advice ,
and did think that what you suggest was in fact exactly what I'm doing.
I'm posting my existing code , with the additional code I need to
incorporate and asking if anyone with greater expertise can help marry
the two.

My existing code actually undoes the toggled settings. I have the code
to produce the settings I need , I just don't know how to put them into
my macro so that the settings remain in place when I run it.

Sorry if I wasn't clear before.

^_^

In article , Dave Peterson
writes
I think that the safest thing to try is to record a macro when you protect a
worksheet and toggle the settings that you want checked.

You'll see the code you need to add to your code.

If you have trouble incorporating the changes, post the recorded macro code
and
I'm sure you'll get help.

Colin Hayes wrote:

Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?

Thanks.

  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Protect_Unprotect Macro modification.

Record a macro when you protect the worksheet with your settings the way you
want.

Post that recorded code.

Colin Hayes wrote:

In article , Dave Peterson
writes
Replace this line:
wkSht.Protect Password:=PWORD
with
wkSht.Protect Password:=PWORD, AllowFormattingRows:=True


Hi Dave

Thanks for getting back. Still no joy , I'm afraid.

I'm highlighting all the rows on the sheet. I run the macro to unprotect
the sheet , and right click. The Hide and Unhide switches in the popup
are activated and in black.

I run the macro to protect the sheet again. Now when I right click the
Hide and unhide switched are greyed out. I need these to be accessible
when the sheet is protected , and would have thought that your
suggestion would have worked.

hmmm - bit stuck now.

This is how it is with your line in place :

' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD, AllowFormattingRows:=True
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

I can't see why this wouldn't work.

Thanks again.

Colin Hayes wrote:

In article , Dave Peterson
writes
I'm not sure which ones you want turned back on:

wkSht.Protect Password:=PWORD

Wksht.Protect password:=PWORD DrawingObjects:=False, Contents:=True, _
Scenarios:= True, AllowFormattingColumns:=True, _
AllowInsertingColumns:=True, AllowInsertingRows:=True, _
AllowDeletingRows:=True, AllowFiltering:=True, AllowFormattingRows:=True

I just chose those at random.



Hi Dave

Ok Thanks. I'm not sure where to place this in the macro - I'm getting
red errors when I try to paste it in. If you could advise on that I'd be
grateful.

It's just row formatting i need switched on.

Thanks


Colin Hayes wrote:

Hi Dave

Thanks for getting back to me on this. I'm grateful for your advice ,
and did think that what you suggest was in fact exactly what I'm doing.
I'm posting my existing code , with the additional code I need to
incorporate and asking if anyone with greater expertise can help marry
the two.

My existing code actually undoes the toggled settings. I have the code
to produce the settings I need , I just don't know how to put them into
my macro so that the settings remain in place when I run it.

Sorry if I wasn't clear before.

^_^

In article , Dave Peterson
writes
I think that the safest thing to try is to record a macro when you protect a
worksheet and toggle the settings that you want checked.

You'll see the code you need to add to your code.

If you have trouble incorporating the changes, post the recorded macro code
and
I'm sure you'll get help.

Colin Hayes wrote:

Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?

Thanks.


--

Dave Peterson


  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Protect_Unprotect Macro modification.

In article , Dave Peterson
writes
Record a macro when you protect the worksheet with your settings the way you
want.

Post that recorded code.


Hi Dave

OK will do.

Thanks again.




Colin Hayes wrote:

In article , Dave Peterson
writes
Replace this line:
wkSht.Protect Password:=PWORD
with
wkSht.Protect Password:=PWORD, AllowFormattingRows:=True


Hi Dave

Thanks for getting back. Still no joy , I'm afraid.

I'm highlighting all the rows on the sheet. I run the macro to unprotect
the sheet , and right click. The Hide and Unhide switches in the popup
are activated and in black.

I run the macro to protect the sheet again. Now when I right click the
Hide and unhide switched are greyed out. I need these to be accessible
when the sheet is protected , and would have thought that your
suggestion would have worked.

hmmm - bit stuck now.

This is how it is with your line in place :

' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD, AllowFormattingRows:=True
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

I can't see why this wouldn't work.

Thanks again.

Colin Hayes wrote:

In article , Dave Peterson
writes
I'm not sure which ones you want turned back on:

wkSht.Protect Password:=PWORD

Wksht.Protect password:=PWORD DrawingObjects:=False,

Contents:=True, _
Scenarios:= True, AllowFormattingColumns:=True, _
AllowInsertingColumns:=True, AllowInsertingRows:=True, _
AllowDeletingRows:=True, AllowFiltering:=True,

AllowFormattingRows:=True

I just chose those at random.



Hi Dave

Ok Thanks. I'm not sure where to place this in the macro - I'm getting
red errors when I try to paste it in. If you could advise on that I'd be
grateful.

It's just row formatting i need switched on.

Thanks


Colin Hayes wrote:

Hi Dave

Thanks for getting back to me on this. I'm grateful for your advice ,
and did think that what you suggest was in fact exactly what I'm doing.
I'm posting my existing code , with the additional code I need to
incorporate and asking if anyone with greater expertise can help marry
the two.

My existing code actually undoes the toggled settings. I have the code
to produce the settings I need , I just don't know how to put them into
my macro so that the settings remain in place when I run it.

Sorry if I wasn't clear before.

^_^

In article , Dave Peterson
writes
I think that the safest thing to try is to record a macro when you protect

a
worksheet and toggle the settings that you want checked.

You'll see the code you need to add to your code.

If you have trouble incorporating the changes, post the recorded macro

code
and
I'm sure you'll get help.

Colin Hayes wrote:

Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?

Thanks.

  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Protect_Unprotect Macro modification.

This works for me...........note the addition of of being able to select locked
cells.

Sub Protect_Unprotect()
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD, DrawingObjects:=True, _
Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True
ActiveSheet.EnableSelection = xlNoRestrictions
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

End Sub


Gord

On Mon, 21 May 2007 12:36:57 +0100, Colin Hayes
wrote:


Hi Gord

Thanks for your help. Still no joy I'm afraid.

I have a workbook of 25 sheets , and I use the macro to unprotect /
protect them all at one go. They are all either protect or unprotected
together and the macro toggles them.

I want to have row formatting available at all times , whether the sheet
is protected of unprotected. I need to be able to hide / unhide rows at
all times.

I find that if I set this manually for a sheet then it works , and
allows me to format rows in protected and unprotected state. The row
formatting commands are available. This is how I want it.

However , after I run the macro below , the ability to format rows is
gone. The row formatting commands are greyed out.

I just need the macro to be amended so it won't overwrite the row
formatting permission. I did try your amendment below , but couldn't
make it work.

So , that's it. Hope you can help.

Thanks.


In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
Colin

Your code toggles protection on/off each sheet so you will have various states
of protection unless you set all sheets first to protected or unprotected.

Is this what you want? Or do you want to protect or unprotect all sheets
together?

The AllowFormattingRows and a couple of other modes have been added below.

Also, CTRL + z is the default Excel UnDo shortcut key. You may want to try
another combo.

Sub Protect_Unprotect()
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD, DrawingObjects:=True, _
Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

End Sub


Gord Dibben MS Excel MVP

On Mon, 21 May 2007 02:45:22 +0100, Colin Hayes

wrote:


Hi Dave

Thanks for getting back to me on this. I'm grateful for your advice ,
and did think that what you suggest was in fact exactly what I'm doing.
I'm posting my existing code , with the additional code I need to
incorporate and asking if anyone with greater expertise can help marry
the two.

My existing code actually undoes the toggled settings. I have the code
to produce the settings I need , I just don't know how to put them into
my macro so that the settings remain in place when I run it.

Sorry if I wasn't clear before.

^_^





In article , Dave Peterson
writes
I think that the safest thing to try is to record a macro when you protect a
worksheet and toggle the settings that you want checked.

You'll see the code you need to add to your code.

If you have trouble incorporating the changes, post the recorded macro code and
I'm sure you'll get help.

Colin Hayes wrote:

Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?

Thanks.




  #13   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Protect_Unprotect Macro modification.


Hi Gord

Thanks for helping on this. I think my machine must be set differently
somehow. Running the macro still switches of all the formatting I need
to stay open on protection. It's a real mystery to me why it continues
to do it , giving the extra code incorporated into it.

I run the macro to unprotect and the row formatting is available , right
clicking on highlighted rows shows this. Run the macro to protect and
it's all greyed out.

If I unprotect / protect manually then all the formatting remains
available , but not if I use the macro. Very strange. I'm clearly
missing something here.

I'm grateful for your efforts over it. Excel can be a very mysterious
program sometimes. I'll have a longer play with it , and I'll let you
know how it goes!



Best Wishes





In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
This works for me...........note the addition of of being able to select locked
cells.

Sub Protect_Unprotect()
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD, DrawingObjects:=True, _
Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True
ActiveSheet.EnableSelection = xlNoRestrictions
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

End Sub


Gord

On Mon, 21 May 2007 12:36:57 +0100, Colin Hayes

wrote:


Hi Gord

Thanks for your help. Still no joy I'm afraid.

I have a workbook of 25 sheets , and I use the macro to unprotect /
protect them all at one go. They are all either protect or unprotected
together and the macro toggles them.

I want to have row formatting available at all times , whether the sheet
is protected of unprotected. I need to be able to hide / unhide rows at
all times.

I find that if I set this manually for a sheet then it works , and
allows me to format rows in protected and unprotected state. The row
formatting commands are available. This is how I want it.

However , after I run the macro below , the ability to format rows is
gone. The row formatting commands are greyed out.

I just need the macro to be amended so it won't overwrite the row
formatting permission. I did try your amendment below , but couldn't
make it work.

So , that's it. Hope you can help.

Thanks.


In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
Colin

Your code toggles protection on/off each sheet so you will have various states
of protection unless you set all sheets first to protected or unprotected.

Is this what you want? Or do you want to protect or unprotect all sheets
together?

The AllowFormattingRows and a couple of other modes have been added below.

Also, CTRL + z is the default Excel UnDo shortcut key. You may want to try
another combo.

Sub Protect_Unprotect()
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD, DrawingObjects:=True, _
Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingRows:=True
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

End Sub


Gord Dibben MS Excel MVP

On Mon, 21 May 2007 02:45:22 +0100, Colin Hayes

wrote:


Hi Dave

Thanks for getting back to me on this. I'm grateful for your advice ,
and did think that what you suggest was in fact exactly what I'm doing.
I'm posting my existing code , with the additional code I need to
incorporate and asking if anyone with greater expertise can help marry
the two.

My existing code actually undoes the toggled settings. I have the code
to produce the settings I need , I just don't know how to put them into
my macro so that the settings remain in place when I run it.

Sorry if I wasn't clear before.

^_^





In article , Dave Peterson
writes
I think that the safest thing to try is to record a macro when you protect a
worksheet and toggle the settings that you want checked.

You'll see the code you need to add to your code.

If you have trouble incorporating the changes, post the recorded macro code

and
I'm sure you'll get help.

Colin Hayes wrote:

Hi

I use this macro to protect and unprotect all the worksheets in my
workbook :

Protect_Unprotect Macro
' Shortcut Ctrl + z
' Protects / Unprotects by turn all sheets in a workbook

'
Const PWORD As String = "12071956"
Dim wkSht As Worksheet
Dim statStr As String

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=PWORD
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)

'
End Sub

it works very well , but unfortunately resets all the protection
parameters to the minimum. I need to add a line to it so that it will
maintain formatting of rows in the protected sheet.

AllowFormattingRows:=True

but I'm not sure where i can incorporate it into the code. Can someone
help?

Thanks.






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 Modification carl Excel Worksheet Functions 0 May 4th 07 04:17 PM
Macro Modification - Bob Philips Are You Out There ? Carl Excel Worksheet Functions 2 September 17th 06 01:56 PM
Macro Modification Carl Excel Worksheet Functions 2 August 30th 06 01:53 PM
Macro modification Hirsch Excel Discussion (Misc queries) 3 May 27th 05 10:21 PM
Macro Modification Help Dmorri254 Excel Worksheet Functions 0 March 4th 05 03:51 PM


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