Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 103
Default specific worksheet protection and auto run

Greetings. Could someone please point me in the right direction with a bit
of code? I have a workbook with 50+ worksheets, but I only need a certain 2
worksheets protected. I also want this macro to run when I close the
workbook, so that I don't have to run the macro myself (I'd probably forget).
Could someone show me how to accomplish this task? Thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default specific worksheet protection and auto run

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Sheets(Array("Sheet2", "Sheet3"))
ws.Protect Password:="justme"
Next ws

End Sub

Entered in ThisWorkbook module.



Gord Dibben MS Excel MVP

On Thu, 4 Oct 2007 16:41:00 -0700, Josh wrote:

Greetings. Could someone please point me in the right direction with a bit
of code? I have a workbook with 50+ worksheets, but I only need a certain 2
worksheets protected. I also want this macro to run when I close the
workbook, so that I don't have to run the macro myself (I'd probably forget).
Could someone show me how to accomplish this task? Thanks


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 103
Default specific worksheet protection and auto run

Thanks!

"Gord Dibben" wrote:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Sheets(Array("Sheet2", "Sheet3"))
ws.Protect Password:="justme"
Next ws

End Sub

Entered in ThisWorkbook module.



Gord Dibben MS Excel MVP

On Thu, 4 Oct 2007 16:41:00 -0700, Josh wrote:

Greetings. Could someone please point me in the right direction with a bit
of code? I have a workbook with 50+ worksheets, but I only need a certain 2
worksheets protected. I also want this macro to run when I close the
workbook, so that I don't have to run the macro myself (I'd probably forget).
Could someone show me how to accomplish this task? Thanks



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 103
Default specific worksheet protection and auto run

With this code, the user would have to push "save" before he/she can close
the document in order for the protection to run. Is there a way to
accomplish the same task without having to save? For instance, if the user
unprotected the worksheet, updated cells, saved, pushed exit (code runs)
pushed "don't save" (user thinking he/she doesn't need to save again), the
worksheet would be unprotected. Thoughts?

"Josh" wrote:

Thanks!

"Gord Dibben" wrote:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Sheets(Array("Sheet2", "Sheet3"))
ws.Protect Password:="justme"
Next ws

End Sub

Entered in ThisWorkbook module.



Gord Dibben MS Excel MVP

On Thu, 4 Oct 2007 16:41:00 -0700, Josh wrote:

Greetings. Could someone please point me in the right direction with a bit
of code? I have a workbook with 50+ worksheets, but I only need a certain 2
worksheets protected. I also want this macro to run when I close the
workbook, so that I don't have to run the macro myself (I'd probably forget).
Could someone show me how to accomplish this task? Thanks



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default specific worksheet protection and auto run

Josh

If user says "No" to saving when closing, the BeforeClose will run anyway.


Gord

On Mon, 8 Oct 2007 17:02:14 -0700, Josh wrote:

With this code, the user would have to push "save" before he/she can close
the document in order for the protection to run. Is there a way to
accomplish the same task without having to save? For instance, if the user
unprotected the worksheet, updated cells, saved, pushed exit (code runs)
pushed "don't save" (user thinking he/she doesn't need to save again), the
worksheet would be unprotected. Thoughts?

"Josh" wrote:

Thanks!

"Gord Dibben" wrote:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Sheets(Array("Sheet2", "Sheet3"))
ws.Protect Password:="justme"
Next ws

End Sub

Entered in ThisWorkbook module.



Gord Dibben MS Excel MVP

On Thu, 4 Oct 2007 16:41:00 -0700, Josh wrote:

Greetings. Could someone please point me in the right direction with a bit
of code? I have a workbook with 50+ worksheets, but I only need a certain 2
worksheets protected. I also want this macro to run when I close the
workbook, so that I don't have to run the macro myself (I'd probably forget).
Could someone show me how to accomplish this task? Thanks





  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default specific worksheet protection and auto run

Maybe I should ask...........did you have a problem with the scenario you
described?

Or did you just not test it?


Gord

On Mon, 08 Oct 2007 19:24:01 -0700, Gord Dibben <gorddibbATshawDOTca wrote:

Josh

If user says "No" to saving when closing, the BeforeClose will run anyway.


Gord

On Mon, 8 Oct 2007 17:02:14 -0700, Josh wrote:

With this code, the user would have to push "save" before he/she can close
the document in order for the protection to run. Is there a way to
accomplish the same task without having to save? For instance, if the user
unprotected the worksheet, updated cells, saved, pushed exit (code runs)
pushed "don't save" (user thinking he/she doesn't need to save again), the
worksheet would be unprotected. Thoughts?

"Josh" wrote:

Thanks!

"Gord Dibben" wrote:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Sheets(Array("Sheet2", "Sheet3"))
ws.Protect Password:="justme"
Next ws

End Sub

Entered in ThisWorkbook module.



Gord Dibben MS Excel MVP

On Thu, 4 Oct 2007 16:41:00 -0700, Josh wrote:

Greetings. Could someone please point me in the right direction with a bit
of code? I have a workbook with 50+ worksheets, but I only need a certain 2
worksheets protected. I also want this macro to run when I close the
workbook, so that I don't have to run the macro myself (I'd probably forget).
Could someone show me how to accomplish this task? 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
auto filters and worksheet protection Joanne Excel Worksheet Functions 3 May 11th 07 05:17 AM
Cell Protection vs. Worksheet Protection kmwhitt Excel Discussion (Misc queries) 4 September 24th 06 02:37 AM
Cell protection & Auto Filter fastballfreddy Excel Worksheet Functions 1 May 11th 06 11:51 AM
Worksheet protection is gone and only wokbook protection can be se Eric C. Excel Discussion (Misc queries) 4 May 2nd 06 04:50 PM
auto protection of cells castro Excel Worksheet Functions 1 March 13th 05 03:24 PM


All times are GMT +1. The time now is 04:51 AM.

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"