View Full Version : Solved: Simple error message

05-01-2009, 06:13 AM
I got a new computer with a new Excel configuration. I'm writting a macro that includes the following simple line:

Set wBook = Workbooks("FilePlan.xls")

and I receive a "Subscript out of range" error (wBook is Empty). I have checked that he file exists and it is in the same directory as the file executing the Macro.

I suspect, there's a Security option preventing me from accessing other files. Any hint? Thanks!!

Kenneth Hobs
05-01-2009, 06:35 AM
That would ok IF it was already open.

You can add the path by ThisWorkBook.Path. e.g.
Sub Test()
Dim wb As Workbook
Set wb = Workbooks.Open(ThisWorkbook.Path & "\ken.xls")
MsgBox ActiveWorkbook.Name
End Sub

Sub TestWhenWBIsOpenAlready()
Dim wb2 As Workbook
Set wb2 = Workbooks("ken.xls")
MsgBox wb2.Name
End Sub

05-01-2009, 06:43 AM
Dim wBook As Workbook
Set wBook = Workbooks.Open(ActiveWorkbook.Path & "\" & "FilePlan.xls")

05-01-2009, 06:44 AM
Ken got here before I refreshed......

05-01-2009, 08:10 AM
Sorry, I thought it worked but not. I don't want to open that Workbook. I just want to access some date on a sheet of a specifique Workbook. How can I access it with a command? I tthought

Workbooks("name").Sheets("Name"). Select shoudl work.

Any hint?

Kenneth Hobs
05-01-2009, 08:44 AM
That is a whole other question.

Is the goal to Select a cell in the other workbook or get the value?

There are 2 methods to get a value, (1) with the workbook closed and (2) with the workbook open.

If the goal is to get a value using method (1), then see: http://www.vbaexpress.com/forum/showthread.php?t=24015

05-01-2009, 08:47 AM
ACK! Sorry Ken; slow fingers...