+ Reply to Thread
Results 1 to 2 of 2

Getting Data from another workbook without opening it

  1. #1
    Registered User
    Join Date
    06-18-2012
    Location
    Leamington SPa
    MS-Off Ver
    Excel 2010
    Posts
    6

    Getting Data from another workbook without opening it

    Hi all,

    I have written code that does exactly what I want it to do; which is find information from another workbook and populate a form so that a user can edit it. The problem is that my code opens the workbook and then closes it again which means that it takes too long. This function will be used hundreds of times a day by a number of users and taking ten seconds each time you open a record is not an option.

    I'm pretty sure that I can do what I want to without opening the other workbook which will save a huge amount of time. Any advice would be greatly appreciated on how to change my code to speed it up: (The bold, italic section is probably the most relevant but I have posted the whole code.)
    Please Login or Register  to view this content.
    Last edited by wattsup; 12-10-2012 at 06:32 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Getting Data from another workbook without opening it

    If you need to directly read from or write to a workbook from VBA, you must open the workbook. Excel formulas in the worksheet can have external references to other workbooks which don't require the workbooks to be open. One alternative might be to put formulas in the workbook someplace that refer to other workbooks, and have the code refer to those values. Another alternative would be to use the code to write those formulas, then read the resulting values (I have never tried this but I can't imagine why it wouldn't work).

    By the way I have a small comment on your code. Using Workbook as a variable name is not advisable because Workbook is also a class name in Excel VBA. Although it will work it can get very confusing in some situations. An alternative here might be WorkbookName. Also
    [code]
    Workbook = "R:\hLog\" & "hLog" & ".xlsm"
    ' Any reason you didn't do this:
    Workbook = "R:\hLog\hLog.xlsm"
    [code]
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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