Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Subscript out of Range

I used the following two methods to determine the existence of a spreadsheet
on one system, but using the same statements on another system I get Error
9, subscript out of Range. Both systems are running Windows XP and Office
2003.
The worksheet does not exist at the time either of these statements are
executed.

If Len(Worksheets("XYZ").Name) 0 then do this or that

Worksheets("XYZ").Activate
If Err.Number < 0 then do this or that

Why do these work on one system and not the other? Is it possible that
there is a setting that needs to be change within Excel to make this work?
Very perplexing. Any assistance would be greatly appreciated. Thank you in
advance.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 266
Default Subscript out of Range

I can't explain your situation, but maybe you'd like to use Allen Browne's
function:

Public Function FileExists(ByVal strFile As String, Optional bFindFolders As
Boolean) As Boolean
'Purpose: Return True if the file exists, even if it is hidden.
'Arguments: strFile: File name to look for. Current directory searched
if no path included.
' bFindFolders. If strFile is a folder, FileExists() returns
False unless this argument is True.
'Note: Does not look inside subdirectories for the file.
'Author: Allen Browne. http://allenbrowne.com June, 2006.
Dim lngAttributes As Long

'Include read-only files, hidden files, system files.
lngAttributes = (vbReadOnly Or vbHidden Or vbSystem)

If bFindFolders Then
lngAttributes = (lngAttributes Or vbDirectory) 'Include folders as
well.
Else
'Strip any trailing slash, so Dir does not look inside the folder.
Do While Right$(strFile, 1) = "\"
strFile = Left$(strFile, Len(strFile) - 1)
Loop
End If

'If Dir() returns something, the file exists.
On Error Resume Next
FileExists = (Len(Dir(strFile, lngAttributes)) 0)
End Function

"Steve" wrote:

I used the following two methods to determine the existence of a spreadsheet
on one system, but using the same statements on another system I get Error
9, subscript out of Range. Both systems are running Windows XP and Office
2003.
The worksheet does not exist at the time either of these statements are
executed.

If Len(Worksheets("XYZ").Name) 0 then do this or that

Worksheets("XYZ").Activate
If Err.Number < 0 then do this or that

Why do these work on one system and not the other? Is it possible that
there is a setting that needs to be change within Excel to make this work?
Very perplexing. Any assistance would be greatly appreciated. Thank you in
advance.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Subscript out of Range

I bet you left off this line, too:

On Error Resume Next

And if you go into the VBE (on both pc's), you'll find a difference in a
setting.

Look at Tools|Options|General tab
One has "Break on all errors" checked (the one that failed).
and the other has one of the other options checked.

I use "break in class module"

Steve wrote:

I used the following two methods to determine the existence of a spreadsheet
on one system, but using the same statements on another system I get Error
9, subscript out of Range. Both systems are running Windows XP and Office
2003.
The worksheet does not exist at the time either of these statements are
executed.

If Len(Worksheets("XYZ").Name) 0 then do this or that

Worksheets("XYZ").Activate
If Err.Number < 0 then do this or that

Why do these work on one system and not the other? Is it possible that
there is a setting that needs to be change within Excel to make this work?
Very perplexing. Any assistance would be greatly appreciated. Thank you in
advance.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Subscript out of Range

Yes, indeed I did. Thanks for the information, it saved the little bit of
hair I have left.

"Dave Peterson" wrote:

I bet you left off this line, too:

On Error Resume Next

And if you go into the VBE (on both pc's), you'll find a difference in a
setting.

Look at Tools|Options|General tab
One has "Break on all errors" checked (the one that failed).
and the other has one of the other options checked.

I use "break in class module"

Steve wrote:

I used the following two methods to determine the existence of a spreadsheet
on one system, but using the same statements on another system I get Error
9, subscript out of Range. Both systems are running Windows XP and Office
2003.
The worksheet does not exist at the time either of these statements are
executed.

If Len(Worksheets("XYZ").Name) 0 then do this or that

Worksheets("XYZ").Activate
If Err.Number < 0 then do this or that

Why do these work on one system and not the other? Is it possible that
there is a setting that needs to be change within Excel to make this work?
Very perplexing. Any assistance would be greatly appreciated. Thank you in
advance.


--

Dave Peterson

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
Error:Subscript out of range Jay Excel Discussion (Misc queries) 1 April 10th 08 10:25 PM
what does 'Subscript Out of range' mean?? Gary Excel Worksheet Functions 2 March 22nd 07 01:33 AM
subscript out of range error in excell Lilivati Excel Discussion (Misc queries) 4 June 26th 06 07:15 PM
9: Subscript out of range jenz21985 Excel Discussion (Misc queries) 6 May 5th 06 03:36 PM
Subscript out of range error moglione1 Excel Discussion (Misc queries) 2 August 30th 05 01:21 PM


All times are GMT +1. The time now is 12:33 PM.

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"