+ Reply to Thread
Results 1 to 17 of 17

error for vba code pulling in another document

  1. #1
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    error for vba code pulling in another document

    I created a code to pull in another excel document of data and I keep getting the error

    "Run-time error '1004';
    Application-defined or object-defining error"

    Here is my code:
    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,541

    Re: error for vba code pulling in another document

    Try removing the last slash ( \ )
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: error for vba code pulling in another document

    Excel can't open a directory; you need to specify a workbook.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: error for vba code pulling in another document

    I tired removing the \ still didn't work.

    What do you mean by specifying a workbook? Isn't that what my code is doing?

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,541

    Re: error for vba code pulling in another document

    No, it's specifying a folder in the R drive.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,541

    Re: error for vba code pulling in another document

    Ah, and, if that's the file name, you would need to add the file extension, for example, .xlsx

  7. #7
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: error for vba code pulling in another document

    Ah thank you that worked! Ok so when I ran the code it pulled up the file I was referencing instead of like pulling the information into the current excel sheet I had open?

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,541

    Re: error for vba code pulling in another document

    You're code just opens the file. It doesn't move the data anywhere.

    What are you trying to do?

  9. #9
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: error for vba code pulling in another document

    I am trying to have the code pull information from one excel doc into the current excel doc my code is in

  10. #10
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: error for vba code pulling in another document

    I added to it and when I click the button to run it, I get an error of "Runtime error '9' Script out of range" Then the debugger highlights the line I have in red below.

    Please Login or Register  to view this content.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,541

    Re: error for vba code pulling in another document

    I am trying to have the code pull information from one excel doc into the current excel doc my code is in
    I kind of gathered that ...

    ... instead of like pulling the information into the current excel sheet I had open?
    Once you have opened the second workbook, you need to select the data you want, copy it, and paste it somewhere in the first workbook. You could copy whole sheets, one or more ranges on one or more sheets, or whatever.

    You can record a macro while you step through the actions manually. That would give you the basic code but it would probably need some tweaking and tidying up.

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,541

    Re: error for vba code pulling in another document

    Ah, our posts overlapped. Try changing
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: error for vba code pulling in another document

    hm I am still getting the error

  14. #14
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: error for vba code pulling in another document

    Now the code is working but for only cells 1 and 40, none in between.

    Please Login or Register  to view this content.

  15. #15
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,541

    Re: error for vba code pulling in another document

    Runtime error '9' Script out of range
    I'm guessing that Sheet1 doesn't exist in one of the workbooks.

    The original line:
    Please Login or Register  to view this content.
    should work, as should my amended version.

    That said, I'm confused if it subsequently works but doesn't copy the right cells.

    Cells(1, 40).EntireColumn is the same as saying Range("AN1").EntireColumn, that is, a single column. That's not what the original copy said, nor the suggested change.

  16. #16
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: error for vba code pulling in another document

    The suggested change you gave keep giving me errors as well. That is why I tried doing the way that is on the last code I posted. The sheet is named "Sheet1" so I am confused on why it is not working.

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,541

    Re: error for vba code pulling in another document

    Please post samples of both workbooks with any sensitive data removed.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Code Error when another Excel document is open
    By Si-Phy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-04-2017, 09:49 AM
  2. Replies: 1
    Last Post: 09-11-2016, 07:40 PM
  3. [SOLVED] Pulling specific word from document name
    By ciapul12 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-14-2014, 07:19 PM
  4. Pulling data into a merge document
    By denfan in forum Excel General
    Replies: 2
    Last Post: 01-07-2014, 04:02 PM
  5. Mail Merge - Excel Document - One field not pulling in
    By degross77 in forum Excel General
    Replies: 0
    Last Post: 08-30-2013, 02:14 PM
  6. [SOLVED] Getting error to vba code for triming the document.
    By satputenandkumar0 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-01-2013, 09:34 AM
  7. pulling specific text from a notepad document
    By smoosh1011 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-06-2009, 05:10 PM

Tags for this Thread

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