Results 1 to 2 of 2
  1. #1
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142

    VBA To Import From Excel

    From a module within my Access database how can I open an excel workbook and force my sub to wait until the workbook finishes refreshing IT'S own data from it's data sources?

    Code:
    Public Sub ImportData()
    On Error GoTo ErrHandler
        Dim ex As Excel.Application
        Dim wb As Excel.Workbook
        
        Debug.Print Now() & " Importing data..."
        
        Set ex = CreateObject("Excel.Application")
        Set wb = ex.Workbooks.Open(DATA_FILE)
    
        'My code shouldn't execute further until wb has refreshed it's own underlying data.
    I have an excel file (raw data) that is processed by a second excel file. This second excel file uses Power Query to quickly parse, filter, sort, preprocess all my data that I then can easily import into my access tables. The power query is set to "Refresh data when opening file". Also, does a workbook even fresh it's own data when I open it from vba in this manner?

    The power query works great and my import code will work to populate the tables fine, no issues there. it just doesn't wait for the workbook to refresh it's data first.

    I've already tried using VBA to import my my data directly from the raw data file but that was turning out to be full of headaches.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You might get good suggestions on alternate methods to crunch or link your data, but in the meantime, here's how you can get Access to wait an arbitrary amount of time. In a standard module:
    Code:
    Public Function Pause(intSecs As Integer)
    Dim Start As Variant
    Start = Timer
    Do While Timer < Start + intSecs
        DoEvents
    Loop
    End Function
    and use as Pause 4. I know of no way to determine from Access if a workbook has finished updating from its data source.
    Last edited by Micron; 03-26-2018 at 02:15 PM. Reason: spelin and gramur
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 02-28-2017, 01:34 AM
  2. Replies: 10
    Last Post: 06-16-2014, 08:37 AM
  3. Import access query data into excel file, using excel vba
    By exceljockey in forum Import/Export Data
    Replies: 3
    Last Post: 11-15-2013, 02:36 PM
  4. Replies: 4
    Last Post: 12-17-2012, 01:21 PM
  5. VBA to open excel, import on close of excel
    By bdaniel in forum Programming
    Replies: 0
    Last Post: 03-20-2010, 02:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums