Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Macro for protecting and unprotecting multiple worksheets

I would say that I am a moderate user of Excel and I need some help with
running a Macro. I have a workbook that has about 60 pages in it that
several people have access to in order to edit information on each of the
sheets. Each sheet has a Vlookup table that I am constantly modifying to
keep items current. My problem is that I am unlocking worksheets all day
long. The password is the same on all of the sheets. Is there a simple
macro I can run to unlock the entire workbook rather than individually
unlocking each sheet? And the same thing when I am finished and putting the
file back. Can I run a macro to reassign the password protection on all of
the sheets in the workbook? Thanks!
--
-CRM
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro for protecting and unprotecting multiple worksheets

Option Explicit
Sub UnprotectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.unprotect password:="topsecret"
next wks
End Sub
Sub ProtectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.protect password:="topsecret"
next wks
End Sub



saltnsnails wrote:

I would say that I am a moderate user of Excel and I need some help with
running a Macro. I have a workbook that has about 60 pages in it that
several people have access to in order to edit information on each of the
sheets. Each sheet has a Vlookup table that I am constantly modifying to
keep items current. My problem is that I am unlocking worksheets all day
long. The password is the same on all of the sheets. Is there a simple
macro I can run to unlock the entire workbook rather than individually
unlocking each sheet? And the same thing when I am finished and putting the
file back. Can I run a macro to reassign the password protection on all of
the sheets in the workbook? Thanks!
--
-CRM


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Macro for protecting and unprotecting multiple worksheets

Thank you but I don't know what to do with that? Where do I enter it? How
do I use it? I am still kind of new to this stuff. Thanks!
--
-CRM


"Dave Peterson" wrote:

Option Explicit
Sub UnprotectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.unprotect password:="topsecret"
next wks
End Sub
Sub ProtectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.protect password:="topsecret"
next wks
End Sub



saltnsnails wrote:

I would say that I am a moderate user of Excel and I need some help with
running a Macro. I have a workbook that has about 60 pages in it that
several people have access to in order to edit information on each of the
sheets. Each sheet has a Vlookup table that I am constantly modifying to
keep items current. My problem is that I am unlocking worksheets all day
long. The password is the same on all of the sheets. Is there a simple
macro I can run to unlock the entire workbook rather than individually
unlocking each sheet? And the same thing when I am finished and putting the
file back. Can I run a macro to reassign the password protection on all of
the sheets in the workbook? Thanks!
--
-CRM


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro for protecting and unprotecting multiple worksheets

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

And while you're in the VBE...
select your poject
Tools|VBAProject Properties|Protection tab
Give it a memorable password.

It'll make finding the password a little more difficult--keep prying eyes out of
your code!

saltnsnails wrote:

Thank you but I don't know what to do with that? Where do I enter it? How
do I use it? I am still kind of new to this stuff. Thanks!
--
-CRM

"Dave Peterson" wrote:

Option Explicit
Sub UnprotectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.unprotect password:="topsecret"
next wks
End Sub
Sub ProtectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.protect password:="topsecret"
next wks
End Sub



saltnsnails wrote:

I would say that I am a moderate user of Excel and I need some help with
running a Macro. I have a workbook that has about 60 pages in it that
several people have access to in order to edit information on each of the
sheets. Each sheet has a Vlookup table that I am constantly modifying to
keep items current. My problem is that I am unlocking worksheets all day
long. The password is the same on all of the sheets. Is there a simple
macro I can run to unlock the entire workbook rather than individually
unlocking each sheet? And the same thing when I am finished and putting the
file back. Can I run a macro to reassign the password protection on all of
the sheets in the workbook? Thanks!
--
-CRM


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Macro for protecting and unprotecting multiple worksheets

OMG!!!! Thank you!!! AWESOME AWESOME AWESOME!!!! The keystrokes I am going
to save!!!! Thanks!
--
-CRM


"Dave Peterson" wrote:

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

And while you're in the VBE...
select your poject
Tools|VBAProject Properties|Protection tab
Give it a memorable password.

It'll make finding the password a little more difficult--keep prying eyes out of
your code!

saltnsnails wrote:

Thank you but I don't know what to do with that? Where do I enter it? How
do I use it? I am still kind of new to this stuff. Thanks!
--
-CRM

"Dave Peterson" wrote:

Option Explicit
Sub UnprotectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.unprotect password:="topsecret"
next wks
End Sub
Sub ProtectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.protect password:="topsecret"
next wks
End Sub



saltnsnails wrote:

I would say that I am a moderate user of Excel and I need some help with
running a Macro. I have a workbook that has about 60 pages in it that
several people have access to in order to edit information on each of the
sheets. Each sheet has a Vlookup table that I am constantly modifying to
keep items current. My problem is that I am unlocking worksheets all day
long. The password is the same on all of the sheets. Is there a simple
macro I can run to unlock the entire workbook rather than individually
unlocking each sheet? And the same thing when I am finished and putting the
file back. Can I run a macro to reassign the password protection on all of
the sheets in the workbook? Thanks!
--
-CRM

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default Macro for protecting and unprotecting multiple worksheets

Dave,
If I wanted to share a workbook that uses this macro to protect/unprotect
the sheets, could it be modified to promt me for the password? Otherwise the
share-ees could run the macro and still gain access.

Thanks for the help,
Bruce

"Dave Peterson" wrote:

Option Explicit
Sub UnprotectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.unprotect password:="topsecret"
next wks
End Sub
Sub ProtectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.protect password:="topsecret"
next wks
End Sub



saltnsnails wrote:

I would say that I am a moderate user of Excel and I need some help with
running a Macro. I have a workbook that has about 60 pages in it that
several people have access to in order to edit information on each of the
sheets. Each sheet has a Vlookup table that I am constantly modifying to
keep items current. My problem is that I am unlocking worksheets all day
long. The password is the same on all of the sheets. Is there a simple
macro I can run to unlock the entire workbook rather than individually
unlocking each sheet? And the same thing when I am finished and putting the
file back. Can I run a macro to reassign the password protection on all of
the sheets in the workbook? Thanks!
--
-CRM


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Macro for protecting and unprotecting multiple worksheets

Option Explicit
Sub UnprotectAll()
Dim wks As Worksheet
Pword = InputBox("enter the password")
On Error GoTo endit
For Each wks In ActiveWorkbook.Worksheets
wks.Unprotect Password:=Pword
Next wks
endit:
MsgBox "Incorrect Password"
End Sub

Correct Pword would be "topsecret" if you used the ProtectAll sub


Gord Dibben MS Excel MVP

On Thu, 24 Jan 2008 13:45:05 -0800, brumanchu
wrote:

Dave,
If I wanted to share a workbook that uses this macro to protect/unprotect
the sheets, could it be modified to promt me for the password? Otherwise the
share-ees could run the macro and still gain access.

Thanks for the help,
Bruce

"Dave Peterson" wrote:

Option Explicit
Sub UnprotectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.unprotect password:="topsecret"
next wks
End Sub
Sub ProtectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.protect password:="topsecret"
next wks
End Sub



saltnsnails wrote:

I would say that I am a moderate user of Excel and I need some help with
running a Macro. I have a workbook that has about 60 pages in it that
several people have access to in order to edit information on each of the
sheets. Each sheet has a Vlookup table that I am constantly modifying to
keep items current. My problem is that I am unlocking worksheets all day
long. The password is the same on all of the sheets. Is there a simple
macro I can run to unlock the entire workbook rather than individually
unlocking each sheet? And the same thing when I am finished and putting the
file back. Can I run a macro to reassign the password protection on all of
the sheets in the workbook? Thanks!
--
-CRM


--

Dave Peterson


  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro for protecting and unprotecting multiple worksheets

You may want to put it in a different workbook and not share that workbook with
the macro.

Then you can open the macro workbook and open the real workbook

And with the real workbook open, you can use:
alt-f8
and run either macro.

====
Or...


Option Explicit
Sub UnprotectAll()
Dim wks As Worksheet
Dim pwd As String
pwd = InputBox(Prompt:="What's the password, Kenny?")

If Trim(pwd) = "" Then
Exit Sub
End If

For Each wks In ActiveWorkbook.Worksheets
With wks
If .ProtectContents = True _
Or .ProtectDrawingObjects = True _
Or .ProtectScenarios = True Then
On Error Resume Next
.Unprotect Password:=pwd
If Err.Number < 0 Then
MsgBox "Something went wrong with: " & wks.Name
Err.Clear
'exit for 'stop trying???
End If
On Error GoTo 0
End If
End With
Next wks

End Sub
Sub ProtectAll()
Dim wks As Worksheet
Dim pwd As String
pwd = InputBox(Prompt:="What's the password, Kenny?")

If Trim(pwd) = "" Then
Exit Sub
End If

For Each wks In ActiveWorkbook.Worksheets
With wks
If .ProtectContents = True _
Or .ProtectDrawingObjects = True _
Or .ProtectScenarios = True Then
'do nothing, it's already protected
Else
On Error Resume Next
.Protect Password:=pwd
If Err.Number < 0 Then
MsgBox "Something went wrong with: " & wks.Name
Err.Clear
'exit for 'stop trying???
End If
On Error GoTo 0
End If
End With
Next wks
End Sub


brumanchu wrote:

Dave,
If I wanted to share a workbook that uses this macro to protect/unprotect
the sheets, could it be modified to promt me for the password? Otherwise the
share-ees could run the macro and still gain access.

Thanks for the help,
Bruce

"Dave Peterson" wrote:

Option Explicit
Sub UnprotectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.unprotect password:="topsecret"
next wks
End Sub
Sub ProtectAll()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.protect password:="topsecret"
next wks
End Sub



saltnsnails wrote:

I would say that I am a moderate user of Excel and I need some help with
running a Macro. I have a workbook that has about 60 pages in it that
several people have access to in order to edit information on each of the
sheets. Each sheet has a Vlookup table that I am constantly modifying to
keep items current. My problem is that I am unlocking worksheets all day
long. The password is the same on all of the sheets. Is there a simple
macro I can run to unlock the entire workbook rather than individually
unlocking each sheet? And the same thing when I am finished and putting the
file back. Can I run a macro to reassign the password protection on all of
the sheets in the workbook? Thanks!
--
-CRM


--

Dave Peterson


--

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
Protecting Multiple Worksheets at the same time Doug P. Excel Worksheet Functions 1 September 20th 07 02:48 AM
Unprotecting worksheets hip Excel Worksheet Functions 4 June 5th 06 07:37 AM
Protecting multiple worksheets. Superjet Excel Discussion (Misc queries) 2 February 2nd 06 07:06 PM
protecting multiple worksheets Sue Excel Discussion (Misc queries) 2 September 12th 05 08:40 PM
PROTECTING/UNPROTECTING SHEETS Maureen Excel Discussion (Misc queries) 1 January 6th 05 06:46 PM


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