Workbook_Open - ActiveSheet.Unprotect not working!
Posted by Michele on October 17, 2001 4:00 AM
I have a one-sheet workbook with this sheet password protected. Upon opening the workbook, in the "ThisWorkbook" module I have in "Private Sub Workbook_Open()" an unprotect, update a cell and then protect again. This works fine when I open the file/workbook directly. However, if I open it via another Excel-workbook/Excel-file it crashes on my udate of the cell saying the cell is protected. I have checked and confirmed that under this indirect open, the unprotect doesn't take place.
Can anyone help? What's wrong with my code? Or what's wrong with Excel/VB
Following is a copy of my code:
Private Sub Workbook_Open()
Application.EnableCancelKey = xlDisabled
ActiveSheet.Protect ("moqrpsw"), DrawingObjects:=True, Contents:=True, Scenarios:=True
Application.CommandBars(1).Enabled = False
Application.CommandBars("Worksheet Menu Bar").Enabled = False
Application.CommandBars("Standard").Visible = False
Application.CommandBars("Formatting").Visible = False
Application.DisplayFormulaBar = False
ActiveWindow.DisplayHeadings = False
Range("HypDate").Select
ActiveWorkSheet.Unprotect ("moqrpsw")
Range("CoName").Value = Left(ActiveWorkbook.Name, 3)
ActiveSheet.Protect ("moqrpsw"), DrawingObjects:=True, Contents:=True, Scenarios:=True
Range("HypDate").Select
Beep
End Sub
Many thanks
Michele