+ Reply to Thread
Results 1 to 6 of 6

Waiting for Workbook to Refresh Before Executing Next Line

  1. #1
    Forum Contributor
    Join Date
    04-23-2014
    Location
    United Kingdom
    MS-Off Ver
    Microsoft 365
    Posts
    149

    Waiting for Workbook to Refresh Before Executing Next Line

    I have a table that is using an ODBC data connection to update. I've created a button that allows the user to refresh this query, but I'm wondering how I can amend the code below so that my Excel workbook finishes refreshing before executing the next line of code — in this case it's to run another macro. I've tried various things including using Do While, but that does not work.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor saravnepali's Avatar
    Join Date
    01-14-2019
    Location
    Sydney Australia
    MS-Off Ver
    2010
    Posts
    447

    Re: Waiting for Workbook to Refresh Before Executing Next Line

    Use application.wait function

    This will make the macro pause for approximately 10 seconds:
    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    If you think someone helped you, click on the "* Add Reputation" as a way to say thank you.

    If your problem is solved, go to Thread Tools and select Mark This Thread Solved

  3. #3
    Forum Contributor
    Join Date
    04-23-2014
    Location
    United Kingdom
    MS-Off Ver
    Microsoft 365
    Posts
    149

    Re: Waiting for Workbook to Refresh Before Executing Next Line

    Thanks, that works. The only thing is that it is based on a timer, so if the workbook hasn't refreshed in time, then the other macro will run — and this could lead to issues.

    Is there a way to explicitly move on to the next part of the code only when the workbook has refreshed — no matter how long it takes.

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Waiting for Workbook to Refresh Before Executing Next Line

    Does adding the indicated line of code work for you...
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    04-23-2014
    Location
    United Kingdom
    MS-Off Ver
    Microsoft 365
    Posts
    149

    Re: Waiting for Workbook to Refresh Before Executing Next Line

    That does work, but only when I disable 'Enable background refresh' in the query's properties window. Thanks.

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Waiting for Workbook to Refresh Before Executing Next Line

    Quote Originally Posted by Statto View Post
    That does work, but only when I disable 'Enable background refresh' in the query's properties window. Thanks.
    I do not work with Queries, so using DoEvents was a guess given what it is supposed to do. Do you consider your question resolved? If so, please mark the thread SOLVED. If not, then another guess on my part... can you turn background refresh off just before the DoEvents and then turn them back on immediately afterwards?

+ 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. Refresh All pivots stops executing further code
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-22-2019, 08:40 AM
  2. Waiting for Query to be executed - waiting forever!
    By BHeup in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 0
    Last Post: 07-01-2018, 11:52 PM
  3. [SOLVED] Waiting command to refresh pivot table
    By kanonathena in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-18-2013, 08:37 PM
  4. worksheet_change. if target.column line not executing
    By Lifeseeker in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2012, 12:39 AM
  5. Err.Number executing Selection.QueryTable.Refresh BackgroundQuery:=False instruction
    By fguilbau in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-30-2009, 12:16 PM
  6. Adding Extra Servers in Waiting Line
    By RatherConfuzed in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-28-2007, 04:37 PM
  7. [SOLVED] Check if workbook is waiting to calculate
    By sime in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2005, 01:06 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