jpmccreary
New Member
- Joined
- Jul 21, 2010
- Messages
- 11
I am using Office 2010. Opening the workbook works fine when not in Protected View. However, anytime it is in Protected View (opening from email) the user gets the following error after clicking Enable Editing:
Run-time error '91':
Object variable or With block variable not set
I ran the debugger and found that all of the code between START and END triggers the error. Is there anyway to prevent this error?
Run-time error '91':
Object variable or With block variable not set
I ran the debugger and found that all of the code between START and END triggers the error. Is there anyway to prevent this error?
Rich (BB code):
Private Sub Workbook_Open()
With Application
.EnableEvents = True
.ScreenUpdating = False
.Calculation = xlCalculationAutomatic
End With
'**** START
With ActiveWindow
.WindowState = xlMaximized
.LargeScroll UP:=65536, ToLeft:=256
.DisplayWorkbookTabs = False
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True
End With
LockAllSheets 'code below
If ActiveWindow.DisplayWorkbookTabs = True Then MsgBox "Tabs are visible", vbOKOnly
With ActiveWorkbook
.Protect Password:=Range("PWW_PWD"), Structure:=True, Windows:=False
If .ProtectStructure = False Then MsgBox "Workbook is Unprotected", vbOKOnly
.Sheets("Home").Select
.Sheets("Home").Shapes("tbReset").Visible = False
End With
'**** END
If ActiveSheet.ProtectContents = False Then MsgBox "Worksheet is Unprotected", vbOKOnly
Application.ScreenUpdating = True
End Sub
Sub LockAllSheets()
Dim i As Integer
Dim Sheet As Worksheet
Dim sPWD As String
sPWD = Range("PWS_PWD")
i = 1
For Each Sheet In Worksheets
With Worksheets(i)
.Protect Password:=sPWD, DrawingObjects:=True, Contents:=True, Scenarios:=True, UserInterFaceOnly:=True
.EnableSelection = xlNoRestrictions
End With
i = i + 1
Next Sheet
End Sub