+ Reply to Thread
Results 1 to 10 of 10

Load array from closed workbook range

  1. #1
    Forum Contributor
    Join Date
    03-05-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    301

    Load array from closed workbook range

    Hi all,

    I am looking to load an array from a range in a closed workbook - that is, a workbook that must remain closed, nor can it be manipulated in anyway.

    I can do this using the following code:

    Please Login or Register  to view this content.
    However, this simply inserts the data into a worksheet. I need it to go into an array.

    How would this be done?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Load array from closed workbook range

    Can't you replace this,
    Please Login or Register  to view this content.
    with this, where arr is the array, declared as Variant but with no dimensions.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    03-05-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    301

    Re: Load array from closed workbook range

    Thanks for the resonse.

    You can only use the .value if you've already inserted the data into the sheet using .formula.

    I need to populate an array only without pulling the data onto a sheet first.

    I'm certain this must be possible but I don't know how this is done.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Load array from closed workbook range

    The only other way I can think would be to use ADO but that might not be appropriate.

    For example the data might not be formatted/structured properly for ADO or the file might get locked when you connect to it.

    Is putting the values on a sheet a definite no go?

    Actually, just thought of another possibility - Evaluate.

  5. #5
    Forum Contributor
    Join Date
    03-05-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    301

    Re: Load array from closed workbook range

    Thanks for the ADO suggestion but I would like to avoid that. I can open a file, get the range and close the file, but this causes saving requirements from the opened sheet when switching between sheets to get data.

    I can create a sheet, populate the sheet with the data, create the array from the sheet, close the sheet. But that slows everything down and isn't really an elegant solution. Unless there is a way to create the sheet as a worksheet in code without actually making a new sheet in the book?

    ADO is a no go and seems to me that it's more trouble than its worth.

    And I've never heard of the evaluate used in this way. Can you provide an example?

  6. #6
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Load array from closed workbook range

    What about accessing the Workbook using "GetObject" and loading the values into an ArrayList.. ?

    Please Login or Register  to view this content.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Load array from closed workbook range

    Why do you want to avoid ADO?

    Also, what 'saving requirements' do you refer to and what switching between sheets would there be?

    This code would open the workbook, grab the data and then close the workbook.

    Please Login or Register  to view this content.

    apo

    I don't think the workbook is open.

  8. #8
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Load array from closed workbook range

    Hi Norrie..

    I initially didn't include the line..
    Please Login or Register  to view this content.
    but without it.. I get the "File in Use" dialogue when i try to later open the file.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Load array from closed workbook range

    apo

    What I mean is the workbook is closed and the OP doesn't want to openness it.

    As far as I can see your code would only work if the workbook was open.

  10. #10
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Load array from closed workbook range

    yeah.. i think you're right.. the Workbook is open.. just not visible..

  11. #11
    Forum Contributor
    Join Date
    03-05-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    301

    Re: Load array from closed workbook range

    Thanks all who contributed to my question.

    The code line below worked exactly to resolve the issue.

    Please Login or Register  to view this content.
    Cheers all and take a rep for the help.

+ 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. Load and unload a user menu, when the workbook open and then is closed again.
    By gnaske in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-01-2013, 05:15 AM
  2. Use ADO to get specific data from closed workbook and fill array
    By wotadude in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-25-2009, 04:27 PM
  3. Load Contents of array into Range
    By additude in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-26-2008, 07:01 PM
  4. Questions on copying range from closed workbook to active workbook
    By stevebriz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2007, 09:45 AM
  5. Load excel range into multi dimensional array
    By Rishi Dhupar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2006, 11:55 AM

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