Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / General Excel Questions / March 2008

Tip: Looking for answers? Try searching our database.

unprotect sheet macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
belvy123 - 27 Mar 2008 22:27 GMT
Hi All

I have a macro that is listed below
It will be used for security  keep people from unauthorized use of my excel
file
Anyways. The macro listed below works gret. However I need to add
additional code to have the macro unprotect each sheet before it can clear
the cells as stated in the original macro.
Is anyone able to help with the code needed to unprotect each sheet.

Private Sub Workbook_Open()
Sheets(1).Activate
If Date > Range("A1").Value Then
   For Each sh In Sheets
       sh.Cells.Clear
   Next
   ActiveWorkbook.Save
End If
End Sub

Thanks

Signature

cruchnin numbers

Dave Peterson - 27 Mar 2008 23:30 GMT
Is it always the same password:

Option Explicit
Private Sub Workbook_Open()
dim Sh as worksheet
dim PWD as string

pwd = "TopSecret

If Date > me.sheets(1).Range("A1").Value Then
   For Each sh In Sheets
       sh.unprotect password:=pwd
       sh.Cells.Clear
       sh.protect password:=pwd
   Next
   me.Save
End If
End Sub

But it really won't stop too many people.  The ones that want your workbook will
just open a backup version with macros disabled (or just stop those autorunning
macros).

> Hi All
>
[quoted text clipped - 20 lines]
> --
> cruchnin numbers

Signature

Dave Peterson

Barb Reinhardt - 27 Mar 2008 23:36 GMT
Try adding sh.unprotect to your For/Next loop.
Signature

HTH,
Barb Reinhardt

> Hi All
>
[quoted text clipped - 17 lines]
>
> Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.