+ Reply to Thread
Results 1 to 6 of 6

Runtime error 9 when trying to reference another workbook

  1. #1
    Registered User
    Join Date
    06-30-2011
    Location
    HK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Runtime error 9 when trying to reference another workbook

    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?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    1,252

    Re: Runtime error 9 when trying to reference another workbook

    Hi,

    You have to open the other workbook before you can read values from it (unless you use ADO).
    Please Login or Register  to view this content.
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Registered User
    Join Date
    06-30-2011
    Location
    HK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Runtime error 9 when trying to reference another workbook

    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:

    Please Login or Register  to view this content.
    but fine for below:
    Please Login or Register  to view this content.
    Last edited by MingVBA; 06-30-2011 at 08:55 AM.

  4. #4
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    1,252

    Re: Runtime error 9 when trying to reference another workbook

    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.

  5. #5
    Registered User
    Join Date
    06-30-2011
    Location
    HK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Runtime error 9 when trying to reference another workbook

    Thank you so much!

  6. #6
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Runtime error 9 when trying to reference another workbook

    Quote Originally Posted by MingVBA View Post
    Please Login or Register  to view this content.
    When you are using Workbooks in your code you are calling the name of the workbook and not the file path. Your example that I quoted would look for a workbook named c:\book2.xlsx instead of book2.xlsx.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1