P
Punsterr
Hi,
I have a routine in ThisWorkbook so that when the workbook is opened,
it first protects the worksheets and workbook so that the user cannot
make changes except where allowed. I also want the workbook to open to
a certain worksheet and cell each time the file is opened. I'm running
into two problems:
First, I've had problems with this workbook such that it opens
minimized and does not allow the option to maximize the screen.
Running this macro while having other Excel workbooks open also tends
to cause the other workbook to have the same problem after that other
file is saved and re-opened separately. Perhaps my macro isn't being
limited to the proper workbook?
Second, when the workbook opens, I get a runtime error 91 object
variable or with block variable not set. This occurs after the
range.select and before the splash.
Any suggestions would be appreciated!
Sub Workbook_Open()
' Maximize all windows
ActiveWorkbook.Unprotect Password:="Password"
Application.WindowState = xlMaximized
ActiveWindow.WindowState = xlMaximized
ActiveWorkbook.Protect Password:="Password", Structure:=True,
Windows:=True
' Opens workbook to Table of Contents cell A1 upon opening the
workbook.
ThisWorkbook.Sheets("Contents").Range("a1").Select
' Show splash screen upon opening the workbook
MySplashForm.Show
' Password-protect all worksheets but lets macros hide/delete
Application.ScreenUpdating = False
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Protect Password:="Password",
userinterfaceonly:=True, AllowFormattingCells:=True,
AllowFormattingColumns:=True, AllowFormattingRows:=True
ws.EnableSelection = xlNoRestrictions
Next ws
Application.ScreenUpdating = True
End Sub
I have a routine in ThisWorkbook so that when the workbook is opened,
it first protects the worksheets and workbook so that the user cannot
make changes except where allowed. I also want the workbook to open to
a certain worksheet and cell each time the file is opened. I'm running
into two problems:
First, I've had problems with this workbook such that it opens
minimized and does not allow the option to maximize the screen.
Running this macro while having other Excel workbooks open also tends
to cause the other workbook to have the same problem after that other
file is saved and re-opened separately. Perhaps my macro isn't being
limited to the proper workbook?
Second, when the workbook opens, I get a runtime error 91 object
variable or with block variable not set. This occurs after the
range.select and before the splash.
Any suggestions would be appreciated!
Sub Workbook_Open()
' Maximize all windows
ActiveWorkbook.Unprotect Password:="Password"
Application.WindowState = xlMaximized
ActiveWindow.WindowState = xlMaximized
ActiveWorkbook.Protect Password:="Password", Structure:=True,
Windows:=True
' Opens workbook to Table of Contents cell A1 upon opening the
workbook.
ThisWorkbook.Sheets("Contents").Range("a1").Select
' Show splash screen upon opening the workbook
MySplashForm.Show
' Password-protect all worksheets but lets macros hide/delete
Application.ScreenUpdating = False
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Protect Password:="Password",
userinterfaceonly:=True, AllowFormattingCells:=True,
AllowFormattingColumns:=True, AllowFormattingRows:=True
ws.EnableSelection = xlNoRestrictions
Next ws
Application.ScreenUpdating = True
End Sub