Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Cam Cam is offline
external usenet poster
 
Posts: 165
Default Macro to protect/unprotect with password

Hi.
I have an Excel Protected template file (2000') that I need to unprotect
several sheets (20) in order to perform work, then protected back with the
same password to distribute to users.
Currently I am doing this manual which can be time consuming. How can I
create a macro to protect/unprotect sheet with a click of a button?
Thanks for any help and suggestion.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Macro to protect/unprotect with password

Public const m_cPassword = "MyPassword"

Public Sub ProtectAll()
Dim wks As Worksheet

Application.ScreenUpdating = False
For Each wks In Worksheets
On Error Resume Next
Select Case Trim(wks.Name)
Case "Start" 'Don't protect the start sheet
Case "Main" 'Don't protect the main sheet
Case Else
wks.Protect m_cPassword
End Select
Next wks
Application.ScreenUpdating = True
End Sub

Public Sub UnProtectAll()
Dim wks As Worksheet

Application.ScreenUpdating = False
For Each wks In Worksheets
On Error Resume Next
wks.Unprotect m_cPassword
Next wks
Application.ScreenUpdating = True
End Sub
--
HTH...

Jim Thomlinson


"Cam" wrote:

Hi.
I have an Excel Protected template file (2000') that I need to unprotect
several sheets (20) in order to perform work, then protected back with the
same password to distribute to users.
Currently I am doing this manual which can be time consuming. How can I
create a macro to protect/unprotect sheet with a click of a button?
Thanks for any help and suggestion.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Macro to protect/unprotect with password

Cam,

This will protect all worksheets in the workbook.
(change protect to unprotect to unprotect all worksheets)
===========================
Dim wksh As Worksheet
Application.ScreenUpdating = False

For Each wksh In ActiveWorkbook.Worksheets
wksh.Protect "password"
Next
Application.ScreenUpdating = True
====================

If you are only protecting some sheets (not all), you will
have to create a loop to identity those sheets.

--
steveB

Remove "AYN" from email to respond
"Cam" wrote in message
...
Hi.
I have an Excel Protected template file (2000') that I need to unprotect
several sheets (20) in order to perform work, then protected back with the
same password to distribute to users.
Currently I am doing this manual which can be time consuming. How can I
create a macro to protect/unprotect sheet with a click of a button?
Thanks for any help and suggestion.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 303
Default Macro to protect/unprotect with password

use this macro "before save"


Sub Seal_File()

For Each sheet In Sheets
On Error Resume Next
sheet.Protect ("spw")
Next
Application.StatusBar = ""
End Sub



and this one could be a special key combination
Sub UNSEAL()
ActiveWorkbook.Unprotect ("spw")
For Each sheet In Sheets
On Error Resume Next
sheet.Unprotect ("spw")
Next
Application.StatusBar = "NOT sealed"
End Sub

Note the application status bar commands(optional)
that way you will see at the bottom of your screen whether the sheet is in
the unprotected mode.


Greetings from New Zealand
Bill K
"Cam" wrote in message
...
Hi.
I have an Excel Protected template file (2000') that I need to unprotect
several sheets (20) in order to perform work, then protected back with the
same password to distribute to users.
Currently I am doing this manual which can be time consuming. How can I
create a macro to protect/unprotect sheet with a click of a button?
Thanks for any help and suggestion.



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
Code to protect/unprotect a sheet using a macro with password FredH Excel Discussion (Misc queries) 5 October 23rd 07 04:49 PM
Please help!!! Using code to password-protect and unprotect... Hawk Excel Programming 6 July 9th 05 10:48 PM
Password - Protect, UnProtect MrAlMackay Excel Programming 5 January 19th 05 07:23 PM
Protect/unprotect sheet with password with VBA? dragontale[_7_] Excel Programming 1 April 19th 04 09:29 PM
Macro to protect and unprotect tetreaultl Excel Programming 1 April 1st 04 06:16 PM


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