ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Load a File Error 9 (https://www.excelbanter.com/excel-programming/401706-load-file-error-9-a.html)

Mike H.

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?

Chip Pearson

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?



Gary Keramidas

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?




sebastienm

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?


Mike H.

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.

Chip Pearson

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.



Mike H.

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?





Dave Peterson

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


All times are GMT +1. The time now is 01:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com