Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 78
Default Macro with protect sheet

I have a macro that is used to clear a form for future use, i.e it selects a
range and deletes it. Some users were experiencing problems using this when
the sheet was protected so I wrote in a line at the beginning and end to
unprotect and then re-protect the sheet. This works fine.

What I want to know is, is it possible to do this but have the sheet
re-protected with a password? I would like to protect with a password to stop
more competent users unprotecting and altering the sheet. I did this but when
the macro unprotects and reprotects it just protects as normal with no
password so this is no good.

The code is:

Sub ClearForm1()
'
' ClearForm1 Macro
' Macro recorded 18/08/2008 by leavt
'

'
ActiveSheet.Unprotect
Range("M37:N38").Select
Selection.Copy
Range("M35:N36").Select
Selection.PasteSpecial Paste:=xlPasteAllExceptBorders,
Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("C2,C8:C11,E8:E11,B12:E13,B14:E15,C16:C31,E1 6:E31,F8:N31").Select
Range("F8").Activate
Range( _

"C2,C8:C11,E8:E11,B12:E13,B14:E15,C16:C31,E16:E31, F8:N31,A40:N41,M37:N38,M35:N36" _
).Select
Range("M35").Activate
Selection.ClearContents
Range("C2").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub



Thanks in advance.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro with protect sheet

Specify the password on the .unprotect and .protect lines:

ActiveSheet.Unprotect password:="topsecret"
'lots of stuff
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, _
Scenarios:=True, password:="topsecret"



Pyrite wrote:

I have a macro that is used to clear a form for future use, i.e it selects a
range and deletes it. Some users were experiencing problems using this when
the sheet was protected so I wrote in a line at the beginning and end to
unprotect and then re-protect the sheet. This works fine.

What I want to know is, is it possible to do this but have the sheet
re-protected with a password? I would like to protect with a password to stop
more competent users unprotecting and altering the sheet. I did this but when
the macro unprotects and reprotects it just protects as normal with no
password so this is no good.

The code is:

Sub ClearForm1()
'
' ClearForm1 Macro
' Macro recorded 18/08/2008 by leavt
'

'
ActiveSheet.Unprotect
Range("M37:N38").Select
Selection.Copy
Range("M35:N36").Select
Selection.PasteSpecial Paste:=xlPasteAllExceptBorders,
Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("C2,C8:C11,E8:E11,B12:E13,B14:E15,C16:C31,E1 6:E31,F8:N31").Select
Range("F8").Activate
Range( _

"C2,C8:C11,E8:E11,B12:E13,B14:E15,C16:C31,E16:E31, F8:N31,A40:N41,M37:N38,M35:N36" _
).Select
Range("M35").Activate
Selection.ClearContents
Range("C2").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

Thanks in advance.


--

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
Macro to re-protect sheet w/ original password after pasting valuesin new book [email protected] Excel Worksheet Functions 1 June 4th 08 04:27 PM
Code to protect/unprotect a sheet using a macro with password FredH Excel Discussion (Misc queries) 5 October 23rd 07 04:49 PM
protect sheet macro problems Nikki Excel Discussion (Misc queries) 2 May 25th 07 04:55 AM
Protect sheet in macro traima Excel Worksheet Functions 3 March 9th 07 06:05 PM
Using macro to un/protect sheet Bonbon Excel Worksheet Functions 2 February 23rd 06 08:14 PM


All times are GMT +1. The time now is 09:41 AM.

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"