Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Protecting & unprotecting worksheets

I have 2 codes I stole from here, one to protect the selected sheets, the other to unprotect them. Obviously I need to be able to run them separatly. I added the first by right clicking the excel logo in upper left and pasted it in. But now how do I enter the second one? I'm really new at VBA and macros...
Public Sub ProtectSelectedSheets
Const PWORD As String = "drowssap"
Dim wkSht As Worksheet
For Each wkSht In ActiveWindow.SelectedSheets
wkSht.Protect Password:=PWORD
Next wkSht
End Sub

Public Sub UnProtectMultipleSheets()
Const Pword As String = "drowssap"
Dim WkSht As Worksheet
For Each WkSht In Worksheets
WkSht.Unprotect Pword
Next WkSht
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 634
Default Protecting & unprotecting worksheets

Put the code in your personal macro workbook. Hit Tools / Macros / Record New
Macro (Choose to storte it in your personal macro Workbook), type a 1 in any
cell, and hit the 'Stop recording' button.

Now Hit ALT+F11 and this will open the VBE (Visual Basic Editor)
Top left you will hopefully see an explorer style pane. Within this pane you
need to search for
your workbook's name, and when you find it you may need to click on the + to
expand it. Within
that you should see the following:-

VBAProject(Personal.xls)
Microsoft Excel Objects
Sheet1(Sheet1)
ThisWorkbook
Modules
Module1

Double click on the module1 and you should see some code like this:-

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 07/01/2004 by Ken Wright
'

'
ActiveCell.FormulaR1C1 = "1"
Range("D9").Select
End Sub

Select all that, delete it and then paste in both the pieces of code you found.
Now just hit File / Save Personal.xls and then do File / Close and return to
Microsoft Excel.

You can now use Tools / Macros / Macro / 'Pick one of the routines' whilst in
any other Excel file.

--
Regards
Ken....................... Microsoft MVP - Excel
Sys Spec - Win XP Pro / XL 00/02/03

----------------------------------------------------------------------------
It's easier to beg forgiveness than ask permission :-)
----------------------------------------------------------------------------



"pkley" wrote in message
...
I have 2 codes I stole from here, one to protect the selected sheets, the

other to unprotect them. Obviously I need to be able to run them separatly. I
added the first by right clicking the excel logo in upper left and pasted it in.
But now how do I enter the second one? I'm really new at VBA and macros...
Public Sub ProtectSelectedSheets
Const PWORD As String = "drowssap"
Dim wkSht As Worksheet
For Each wkSht In ActiveWindow.SelectedSheets
wkSht.Protect Password:=PWORD
Next wkSht
End Sub

Public Sub UnProtectMultipleSheets()
Const Pword As String = "drowssap"
Dim WkSht As Worksheet
For Each WkSht In Worksheets
WkSht.Unprotect Pword
Next WkSht
End Sub



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.558 / Virus Database: 350 - Release Date: 02/01/2004


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
Protecting and Unprotecting several worksheets at one time Learning Excel Excel Discussion (Misc queries) 8 February 4th 09 10:07 PM
protecting and unprotecting Fusion1337 Excel Worksheet Functions 5 September 26th 08 04:03 PM
Macro for protecting and unprotecting multiple worksheets saltnsnails Excel Discussion (Misc queries) 7 January 24th 08 10:49 PM
PROTECTING/UNPROTECTING SHEETS Maureen Excel Discussion (Misc queries) 1 January 6th 05 06:46 PM
Protecting and Unprotecting multiple sheets pkley Excel Programming 3 January 22nd 04 05:26 PM


All times are GMT +1. The time now is 03:55 PM.

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"