Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Runtimem Error 9 Subscript Out of Range

Its my first time posting a question so bear with me.

My application has an auto-open macro which displays an advanced user form
(i.e. frm___.Show), which then activates a work sheet to populate the form
with data from the worksheet. I get €śRuntime error 9 subscript out of range€ť
on the €śWorksheets(€śWorkSheetName€ť).Activate if another Excel work book is
already open prior to my opening the application. My guess is that its
because the open workbook does not contain the worksheet that Im trying to
activate.

I can avoid this by shutting down all open instances of Excel prior to
opening my application but in order to make my application end user proof Id
like to see if there is a way of bypassing this problem. Id like to have
the application open without problems even when another Excel instance is
already opened since the end users may not be knowledgeable enough to close
down all Excel prior to opening the application.

Thanks for any advice you can provide.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Runtimem Error 9 Subscript Out of Range

Try this

Thisworkbook.Activate

before the code

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Pietersz" wrote in message
...
It's my first time posting a question so bear with me.

My application has an auto-open macro which displays an advanced user form
(i.e. frm___.Show), which then activates a work sheet to populate the form
with data from the worksheet. I get "Runtime error 9 subscript out of

range"
on the "Worksheets("WorkSheetName").Activate if another Excel work book is
already open prior to my opening the application. My guess is that it's
because the open workbook does not contain the worksheet that I'm trying

to
activate.

I can avoid this by shutting down all open instances of Excel prior to
opening my application but in order to make my application end user proof

I'd
like to see if there is a way of bypassing this problem. I'd like to have
the application open without problems even when another Excel instance is
already opened since the end user's may not be knowledgeable enough to

close
down all Excel prior to opening the application.

Thanks for any advice you can provide.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Runtimem Error 9 Subscript Out of Range

dim sh as Worksheet
Thisworkbook.Activate
On Error Resume Next
set sh = Thisworkbook.Worksheets(€śWorkSheetName€ť)
On Error goto 0
if sh is nothing then
msgbox "WorksheetName does not exit in workbook " & _
Thisworkbook.name
ThisWorkbook.Close SaveChanges:=False
end if

--
Regards,
Tom Ogilvy

"Pietersz" wrote:

Its my first time posting a question so bear with me.

My application has an auto-open macro which displays an advanced user form
(i.e. frm___.Show), which then activates a work sheet to populate the form
with data from the worksheet. I get €śRuntime error 9 subscript out of range€ť
on the €śWorksheets(€śWorkSheetName€ť).Activate if another Excel work book is
already open prior to my opening the application. My guess is that its
because the open workbook does not contain the worksheet that Im trying to
activate.

I can avoid this by shutting down all open instances of Excel prior to
opening my application but in order to make my application end user proof Id
like to see if there is a way of bypassing this problem. Id like to have
the application open without problems even when another Excel instance is
already opened since the end users may not be knowledgeable enough to close
down all Excel prior to opening the application.

Thanks for any advice you can provide.

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
Subscript out of range error Vishal[_3_] Excel Programming 3 January 4th 06 11:14 PM
Type Mismatch error & subscript out of range error Jeff Wright[_2_] Excel Programming 3 May 14th 05 07:14 PM
subscript out of range error Darren Excel Programming 3 November 24th 04 03:38 PM
Subscript Out Of Range Error? Michael Vaughan Excel Programming 3 November 9th 04 11:35 AM
Subscript out of range error Gary[_4_] Excel Programming 1 August 13th 03 07:20 AM


All times are GMT +1. The time now is 03:43 AM.

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

About Us

"It's about Microsoft Excel"