PC Review


Reply
Thread Tools Rate Thread

auto-protect a sheet upon workbook close

 
 
ryguy7272
Guest
Posts: n/a
 
      7th Oct 2009
Hi, I am trying to auto-protect a sheet upon workbook close (so people a
certain person doesn’t forget to reapply protection when closing out of a
file that he maintains).
The below macro works fine, but disables ALL options for the user.
Sub ApplySecurity()
Worksheets("Master").Protect Password:="1225"
End Sub

I’d like to allow the user to a few basic things, such as select
locked/unlocked cells, use auto filter, and edit objects.

Sub ApplySecurity()
Worksheets("Master").Protect DrawingObjects:=False, Contents:=True,
Scenarios:= _
True, AllowFiltering:=True Worksheets("Master").Protect

End Sub

How do I add the password in there? I’ve tried a couple things; I get only
errors.

In ThisWorkbook, I’ve got:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call ApplySecurity
End Sub

Private Sub Workbook_Open()
Call ApplySecurity
End Sub

Thanks,
Ryan--

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      7th Oct 2009
Hi,

Like this

Sub ApplySecurity()
Worksheets("Master").Protect Password:="1234", DrawingObjects:=False, _
Contents:=True, Scenarios:=True, AllowFiltering:=True

End Sub

"ryguy7272" wrote:

> Hi, I am trying to auto-protect a sheet upon workbook close (so people a
> certain person doesn’t forget to reapply protection when closing out of a
> file that he maintains).
> The below macro works fine, but disables ALL options for the user.
> Sub ApplySecurity()
> Worksheets("Master").Protect Password:="1225"
> End Sub
>
> I’d like to allow the user to a few basic things, such as select
> locked/unlocked cells, use auto filter, and edit objects.
>
> Sub ApplySecurity()
> Worksheets("Master").Protect DrawingObjects:=False, Contents:=True,
> Scenarios:= _
> True, AllowFiltering:=True Worksheets("Master").Protect
>
> End Sub
>
> How do I add the password in there? I’ve tried a couple things; I get only
> errors.
>
> In ThisWorkbook, I’ve got:
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> Call ApplySecurity
> End Sub
>
> Private Sub Workbook_Open()
> Call ApplySecurity
> End Sub
>
> Thanks,
> Ryan--
>
> --
> Ryan---
> If this information was helpful, please indicate this by clicking ''Yes''.

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      7th Oct 2009
Hi,

I should have added that your calls to this sub will work fine

Mike

"Mike H" wrote:

> Hi,
>
> Like this
>
> Sub ApplySecurity()
> Worksheets("Master").Protect Password:="1234", DrawingObjects:=False, _
> Contents:=True, Scenarios:=True, AllowFiltering:=True
>
> End Sub
>
> "ryguy7272" wrote:
>
> > Hi, I am trying to auto-protect a sheet upon workbook close (so people a
> > certain person doesn’t forget to reapply protection when closing out of a
> > file that he maintains).
> > The below macro works fine, but disables ALL options for the user.
> > Sub ApplySecurity()
> > Worksheets("Master").Protect Password:="1225"
> > End Sub
> >
> > I’d like to allow the user to a few basic things, such as select
> > locked/unlocked cells, use auto filter, and edit objects.
> >
> > Sub ApplySecurity()
> > Worksheets("Master").Protect DrawingObjects:=False, Contents:=True,
> > Scenarios:= _
> > True, AllowFiltering:=True Worksheets("Master").Protect
> >
> > End Sub
> >
> > How do I add the password in there? I’ve tried a couple things; I get only
> > errors.
> >
> > In ThisWorkbook, I’ve got:
> > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > Call ApplySecurity
> > End Sub
> >
> > Private Sub Workbook_Open()
> > Call ApplySecurity
> > End Sub
> >
> > Thanks,
> > Ryan--
> >
> > --
> > Ryan---
> > If this information was helpful, please indicate this by clicking ''Yes''.

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      7th Oct 2009
So weird; thought I tried that. I probably forgot the comma after the
password. Thanks MikeH!!!
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Mike H" wrote:

> Hi,
>
> Like this
>
> Sub ApplySecurity()
> Worksheets("Master").Protect Password:="1234", DrawingObjects:=False, _
> Contents:=True, Scenarios:=True, AllowFiltering:=True
>
> End Sub
>
> "ryguy7272" wrote:
>
> > Hi, I am trying to auto-protect a sheet upon workbook close (so people a
> > certain person doesn’t forget to reapply protection when closing out of a
> > file that he maintains).
> > The below macro works fine, but disables ALL options for the user.
> > Sub ApplySecurity()
> > Worksheets("Master").Protect Password:="1225"
> > End Sub
> >
> > I’d like to allow the user to a few basic things, such as select
> > locked/unlocked cells, use auto filter, and edit objects.
> >
> > Sub ApplySecurity()
> > Worksheets("Master").Protect DrawingObjects:=False, Contents:=True,
> > Scenarios:= _
> > True, AllowFiltering:=True Worksheets("Master").Protect
> >
> > End Sub
> >
> > How do I add the password in there? I’ve tried a couple things; I get only
> > errors.
> >
> > In ThisWorkbook, I’ve got:
> > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > Call ApplySecurity
> > End Sub
> >
> > Private Sub Workbook_Open()
> > Call ApplySecurity
> > End Sub
> >
> > Thanks,
> > Ryan--
> >
> > --
> > Ryan---
> > If this information was helpful, please indicate this by clicking ''Yes''.

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      7th Oct 2009
Your welcome and thanks for the feedback

"ryguy7272" wrote:

> So weird; thought I tried that. I probably forgot the comma after the
> password. Thanks MikeH!!!
> Ryan---
>
> --
> Ryan---
> If this information was helpful, please indicate this by clicking ''Yes''.
>
>
> "Mike H" wrote:
>
> > Hi,
> >
> > Like this
> >
> > Sub ApplySecurity()
> > Worksheets("Master").Protect Password:="1234", DrawingObjects:=False, _
> > Contents:=True, Scenarios:=True, AllowFiltering:=True
> >
> > End Sub
> >
> > "ryguy7272" wrote:
> >
> > > Hi, I am trying to auto-protect a sheet upon workbook close (so people a
> > > certain person doesn’t forget to reapply protection when closing out of a
> > > file that he maintains).
> > > The below macro works fine, but disables ALL options for the user.
> > > Sub ApplySecurity()
> > > Worksheets("Master").Protect Password:="1225"
> > > End Sub
> > >
> > > I’d like to allow the user to a few basic things, such as select
> > > locked/unlocked cells, use auto filter, and edit objects.
> > >
> > > Sub ApplySecurity()
> > > Worksheets("Master").Protect DrawingObjects:=False, Contents:=True,
> > > Scenarios:= _
> > > True, AllowFiltering:=True Worksheets("Master").Protect
> > >
> > > End Sub
> > >
> > > How do I add the password in there? I’ve tried a couple things; I get only
> > > errors.
> > >
> > > In ThisWorkbook, I’ve got:
> > > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > > Call ApplySecurity
> > > End Sub
> > >
> > > Private Sub Workbook_Open()
> > > Call ApplySecurity
> > > End Sub
> > >
> > > Thanks,
> > > Ryan--
> > >
> > > --
> > > Ryan---
> > > If this information was helpful, please indicate this by clicking ''Yes''.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto-Protect Sheet on Open and on Close ryguy7272 Microsoft Excel Programming 3 6th Oct 2009 07:00 PM
Protect WorkBook & Sheet Steven Chan Microsoft Excel Misc 3 25th Sep 2009 02:35 AM
Protect Workbook Vs Protect Sheet =?Utf-8?B?UG9vcl9wYWtpc3Rhbmk=?= Microsoft Excel New Users 4 25th May 2006 02:06 PM
Excel - protect sheet vs. protect workbook =?Utf-8?B?RGlydGJ5a2VEaXZh?= Microsoft Excel Misc 3 1st Sep 2004 02:10 AM
Best Way to protect sheet & workbook with VB =?Utf-8?B?Q0RvdFdpbg==?= Microsoft Excel Programming 1 24th Jul 2004 12:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:02 AM.