ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Subscript out of range problem (https://www.excelbanter.com/excel-programming/310042-re-subscript-out-range-problem.html)

Tom Ogilvy

Subscript out of range problem
 
This assumes the referenced workbook is open.

Even though you have verified the spelling is correct, it is incorrect or
you wouldn't get the error (assuming that line causes the error).

Assuming the book is the activewindow when you run the code.

Dim wndw as Window
set wndw = Activewindow
Workbooks.Open Filename:= _
"C:\My Documents\cat.xls"

wndw.Activate

msgbox "-" & lcase(Application.Substitute(activeworkbook.Name," ","_")) _
& "<-" & vbnewline & _
lcase(Application.Substitute("-C C Schedule Regular.xls<-"," ","_"))

otherwise
Dim bk as Workbook
Workbooks.Open Filename:= _
"C:\My Documents\cat.xls"
for each bk in Workbooks
if instr(1,bk.Name,"Sched",vbTextCompare")0 then
bk.Activate
exit for
End if
Next

Or check the spelling again - might have two spaces where you only think
there is one.

--
Regards,
Tom Ogilvy





"Darrell Wesley" wrote in message
...
The following lines of code yield a "Subscript out of range" error 9.


Workbooks.Open Filename:= _
"C:\My Documents\cat.xls"
Windows("C C Schedule Regular.xls").Activate

Both xls documents are in the same folder and spelling including spaces

has
been verified as correct. Why does this yield a Subscipt out of range

error?





All times are GMT +1. The time now is 08:33 AM.

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