Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Range.Select error and screen maximizing error in Workbook_Open()

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", Structu=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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Range.Select error and screen maximizing error in Workbook_Open()

In order to select a range first you have to select a sheet then select a
range. You can not do it all in one line... Something like this.

Sheets("Contents").select
Range("a1").Select
--
HTH...

Jim Thomlinson


"Punsterr" wrote:

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", Structu=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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Range.Select error and screen maximizing error in Workbook_Open()

ThisWorkbook.Sheets("Contents").Range("a1").Sele ct

This will work only if Contents is the active sheet. Otherwise you should
activate the sheet first and then select the cell. To do it in one step you
have to use Application.Goto.

--
Jim
"Punsterr" wrote in message
oups.com...
| 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", Structu=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
|


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Range.Select error and screen maximizing error in Workbook_Open()

Thanks, Jim. That fixed one part of the problem. I am still, however,
having the runtime error. This is where things get interesting. If I
save the Excel file to my hard drive or to a network, the Workbook Open
function works fine. However, if I attach this file to a Lotus Notes
database and open the file from within the database, the runtime error
91 appears on the very first line of code - where I'm trying to
unprotect the workbook. Any thoughts as to why that might be?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't select range. Why the error? agentsmith83 Excel Programming 1 April 18th 06 04:38 PM
Help with this error Unknown reason for error with Range().Select Brad Sumner Excel Programming 1 September 13th 05 04:24 PM
Range Select Error sailingdan Excel Programming 1 June 14th 04 04:24 PM
Workbook_Open() Error Minitman[_4_] Excel Programming 5 April 2nd 04 07:59 PM
Run-time 1004 error on range select Morgan[_3_] Excel Programming 3 November 11th 03 11:44 PM


All times are GMT +1. The time now is 04:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"