Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Load a File Error 9

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike H. - 26 Nov 2007 21:19 GMT
After loading a file when I issue the command

Windows(TheWb).Activate

where TheWB is the name of the file (with or without the path, doesn't
matter), I am getting an error:  "Runtime Error 9, Subscript out of range".  
What do I need to change?
Chip Pearson - 26 Nov 2007 21:28 GMT
Use the .xls extension in the file name. E.g.,

Windows("Book1.xls").Activate
instead of
Windows("Book1").Activate

Signature

Cordially,
Chip Pearson
Microsoft MVP  - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

> After loading a file when I issue the command
>
[quoted text clipped - 4 lines]
> range".
> What do I need to change?
Mike H. - 26 Nov 2007 21:36 GMT
If I have the filename "xxx.xls" in place of the variable thewb or if I have
the variable thewb which = xxx.xls, I still get the same error, #9, Subscript
error.
Chip Pearson - 26 Nov 2007 21:48 GMT
Do you have multiple windows of the same workbook open? If you do, you'll
see something like

FileName.xls:1
or
FileName.xls:2

in the title bar of Excel. If this is the case, you must include the window
number in the Windows reference. E.g.,

Windows("Book1.xls:1").Close

Or, you can close all but one window with code like

With Workbooks("Book1.xls").Windows
   Do Until .Count = 1
       .Item(1).Close
   Loop
End With

Signature

Cordially,
Chip Pearson
Microsoft MVP  - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

> If I have the filename "xxx.xls" in place of the variable thewb or if I
> have
> the variable thewb which = xxx.xls, I still get the same error, #9,
> Subscript
> error.
Gary Keramidas - 26 Nov 2007 21:31 GMT
something like this:

Sub test2()
Dim fPath As String
Dim fname As String

Dim wb2 As Workbook
fPath = "D:\My Documents\Excel\"
fname = fPath & "Book1.xls"
Set wb2 = Workbooks.Open(Filename:=fname)
Windows(wb2.Name).Activate
End Sub

Signature

Gary

> After loading a file when I issue the command
>
[quoted text clipped - 3 lines]
> matter), I am getting an error:  "Runtime Error 9, Subscript out of range".
> What do I need to change?
Mike H. - 26 Nov 2007 22:55 GMT
I don't know what is going on, but I am still getting the same error 9
subscript out of range when I use even this code.  

> something like this:
>
[quoted text clipped - 16 lines]
> > matter), I am getting an error:  "Runtime Error 9, Subscript out of range".
> > What do I need to change?
Dave Peterson - 26 Nov 2007 23:56 GMT
How about just using:
    wb2.activate

> I don't know what is going on, but I am still getting the same error 9
> subscript out of range when I use even this code.
[quoted text clipped - 23 lines]
> > > matter), I am getting an error:  "Runtime Error 9, Subscript out of range".
> > > What do I need to change?

Signature

Dave Peterson

sebastienm - 26 Nov 2007 21:36 GMT
Hi
What about the extension (with/without)
Also you could do something like:
  Dim Wbk as workbook
  Set Wbk= Workbooks.Open ( .... your file ....)  ''' returns the opened
book into a variable
  Wbk.Windows(1).Activate

Signature

Regards,
Sébastien
<http://www.ondemandanalysis.com>

> After loading a file when I issue the command
>
[quoted text clipped - 3 lines]
> matter), I am getting an error:  "Runtime Error 9, Subscript out of range".  
> What do I need to change?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.