+ Reply to Thread
Results 1 to 6 of 6

Excel VBA to get data from a file without opening it

  1. #1
    Registered User
    Join Date
    12-10-2018
    Location
    toronto
    MS-Off Ver
    2010
    Posts
    11

    Excel VBA to get data from a file without opening it

    I have a code to extract data from a closed worksheet, but I keep getting an error (See the attached pictureerror.PNG)

    So what I'm trying to do is open a file whose name keeps changing. I have the path to the file (including the file name) in an Instructions sheet in cell C29.
    The name of the sheet I'm trying to open also changes, it's called "C18 Summary", so the value 18 is defined in the instructions sheet in Cell C23. And form this sheet the range I'm trying to copy is A61:R66.

    I think the error is, and correct me if I'm wrong, but the file I trying to open in Cell 29 is not actually being opened?

    How did I fix this??

    Please Login or Register  to view this content.
    Last edited by leenz; 12-14-2018 at 05:16 PM.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,880

    Re: Excel VBA to get data from a file without opening it

    I'd recommend you upload sample workbooks (source and output files).

    To upload use "Go Advanced" button and follow "Manage Attachments" hyperlink. It will launch new tab/window for managing uploads.

    What the error is saying, basically file name/table does not exist. Meaning you have syntax for the table/range wrong and/or something else wrong in connection string.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    12-10-2018
    Location
    toronto
    MS-Off Ver
    2010
    Posts
    11

    Re: Excel VBA to get data from a file without opening it

    The file I want to open is C18 P9 File - Super basic file I just created with the range I want is A61:R66 in "C18 Summary". I want to copy this table and paste it in FOREX Forecast in the sample file

    (My code is already in the sample file)
    Attached Files Attached Files

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,880

    Re: Excel VBA to get data from a file without opening it

    You had unnecessary space after " Summary".

    Modify your code to reflect below and it will work.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-10-2018
    Location
    toronto
    MS-Off Ver
    2010
    Posts
    11

    Re: Excel VBA to get data from a file without opening it

    Thank you that worked!! Do you know how I code modify the code to keep the source format?

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,880

    Re: Excel VBA to get data from a file without opening it

    You can't.

    ADO (or any other query tool reading from closed workbook) is meant to bring in data set, not formatting etc. Though you can specify data type, you can't control font/cell format etc.

+ 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. Copy data without opening excel file
    By Ichise in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-16-2017, 02:43 AM
  2. VBA edit help - copy data from an excel without opening the file first
    By TollemG in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-26-2017, 12:59 PM
  3. Iserting data in excel file without opening of that
    By afshingivi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-15-2015, 05:02 AM
  4. Replies: 2
    Last Post: 09-08-2015, 12:11 AM
  5. Replies: 1
    Last Post: 07-11-2015, 01:04 AM
  6. Replies: 2
    Last Post: 05-31-2014, 02:05 AM
  7. Retrieve Data without opening excel file
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-09-2012, 07:51 AM

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