PDA

View Full Version : Subscript out of range



Jake02
10-06-2007, 05:30 PM
I'm new to VB, and I was given a program written in VBA within Excel to modify for a new situation. My only (apparent) obstacle is with anything that starts Workbooks. , such as

Workbooks("BUILDQUIRIES.xls").Activate

I keep getting a run-time error '9' stating that "subscript is out of range" or run-time error '1004' that your file "could not be found."

Can someone PLEASE help me?!?

Aussiebear
10-06-2007, 05:54 PM
Check the spelling of the file name or in fact that it exists.

Jake02
10-06-2007, 06:07 PM
I already checked the spelling and yes, it exists.

lucas
10-06-2007, 07:35 PM
is it open? It won't be found just because it exists...


Workbooks.Open Filename:="D:\Desktop\BUILDQUIRIES.xls"

adjust the path.

Cyberdude
10-07-2007, 10:29 AM
You might want to add a couple of statements to the Lucas statement to take of the case where the workbook is already open:
On Error Resume Next
Workbooks.Open Filename:="D:\Desktop\BUILDQUERIES.xls"
On Error GoTo 0 This would prevent an error interrupt in case the file is already open when you try to open it.