Hi all
I wrote below code to refer to another work but got runtime 09 error, would you please point out what mistake I had made?
Dim Currentpath As Variant Currentpath = "C:\" MsgBox Workbooks(Currentpath & "book1.xls").Sheets("Sheet1").Range("A1").Value
Hi,
You have to open the other workbook before you can read values from it (unless you use ADO).
Dim Currentpath As String Dim wkbTest As Workbook Currentpath = "C:\" Set wkbTest = Workbooks.Open(Currentpath & "book1.xls") MsgBox wkbTest.Sheets("Sheet1").Range("A1").Value
Thanks and I fixed the problem.
One more question, is it not necessary to provide the full path of the file? as I found problem in below code:
but fine for below:Workbooks("c:\book2.xlsx").Sheets("Sheet1").Range("A1")
Workbooks("book2.xlsx").Sheets("Sheet1").Range("A1")
Last edited by MingVBA; 06-30-2011 at 08:55 AM.
When you are opening the file, it's better to use the full file path, otherwise it assumes the current directory. Once the file is open and you want to refer to it in the Workbooks collection, don't use the full path - as per your example.
Thank you so much!
Please leave a message after the beep!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks