Activate WorkBook
I'm betting that FileNameNew includes a drive, a path, and the filename:
c:\my documents\excel\book999.xls
If that's the case, then
windows(filenamenew)
won't work.
It'll want a name of the window--and that name won't include the drive or path.
I'd use:
Dim FileNameNew as String
dim wkbk as workbook
filenamenew = "c:\my documents\excel\book999.xls"
set wkbk = Workbooks.Open(filename:=FileNameNew)
wkbk.activate
I'd go through the workbook collection, too--not the windows collection. If
there are multiple windows into that workbook open (book999.xls:1 and
book999.xls:2 would be in the titlebar), then windows() could fail.
geebee wrote:
hi,
I am getting a "runtime error 9: subscript out of range" when I try to open
a workbook:
Dim FileNameNew as String
Workbooks.Open FileNameNew
Windows(FileNameNew).Activate
The FileNameNew itself has an OnOpen event. Could this be causing the
problem?
How can I get around this? I just want to be able to Activate the
FileNameNew without going through this error message and possibly its OnOpen
event.
Thanks in advance,
geebee
--
Dave Peterson
|