Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Load a File Error 9

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Load a File Error 9

Use the .xls extension in the file name. E.g.,

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


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


"Mike H." wrote in message
...
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?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Load a File Error 9

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.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Load a File Error 9

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


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


"Mike H." wrote in message
...
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.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Load a File Error 9

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

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


"Mike H." wrote:

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?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Load a File Error 9

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



--


Gary


"Mike H." wrote in message
...
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?



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Load a File Error 9

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.

"Gary Keramidas" wrote:

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



--


Gary


"Mike H." wrote in message
...
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?




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Load a File Error 9

How about just using:
wb2.activate


Mike H. wrote:

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.

"Gary Keramidas" wrote:

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



--


Gary


"Mike H." wrote in message
...
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?





--

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
Getting error with load/unload of UserForms?? Ed from AZ Excel Programming 2 August 22nd 07 04:21 PM
Validation Load Error RhysPieces Excel Discussion (Misc queries) 0 June 8th 07 07:08 PM
cannot load excel file - "too many different cell formats" error s Richard Bailey Excel Discussion (Misc queries) 3 May 15th 05 12:33 PM
Is it possible to load an .xls file Jako[_55_] Excel Programming 2 August 2nd 04 11:29 PM
new error when try to load userform izchk shtifman Excel Programming 1 December 30th 03 06:09 PM


All times are GMT +1. The time now is 01:38 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"