+ Reply to Thread
Results 1 to 5 of 5

execute code after finished refresh web query connection

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-18-2014
    Location
    hk
    MS-Off Ver
    Excel 365
    Posts
    105

    execute code after finished refresh web query connection

    Hi All,

    I have a connection which is web query. I want to use macro to refresh the connection. after refresh, I want to process other code.
    Would you help to revise me an idea to do that? Thanks.
    let say,

    Sub test()
    Connections("ABC").refresh //It is a web query connection
    <code to wait the connection finish refreshing.>
    msgbox "finished refreshing"
    processA
    End Sub
    Last edited by JBeaucaire; 01-07-2015 at 12:09 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: execute code after finished refresh web query connection

    Try inserting a line of code:

    DoEvents
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    02-18-2014
    Location
    hk
    MS-Off Ver
    Excel 365
    Posts
    105

    Re: execute code after finished refresh web query connection

    Quote Originally Posted by JBeaucaire View Post
    Try inserting a line of code:

    DoEvents
    Hi Jerry,

    Still not ok.
    Sub test()
    ActiveWorkbook.Connections("Connection").Refresh
    DoEvents
    Application.Wait Now + TimeValue("0:00:01")
    MsgBox ("OK")
    End Sub
    I run the above code. I get a "ok" message before the connection refresh.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: execute code after finished refresh web query connection

    Then the trick will be to insure the BackGroundQuery=False parameter is set in your actual connection. Can you edit your original connections to set that?

    If not, maybe you can adapt something like this:
    Sub Refresh_All_Data_Connections()
    
        For Each objConnection In ThisWorkbook.Connections
            'Get current background-refresh value
            bBackground = objConnection.OLEDBConnection.BackgroundQuery
    
            'Temporarily disable background-refresh
            objConnection.OLEDBConnection.BackgroundQuery = False
    
            'Refresh this connection
            objConnection.Refresh
    
            'Set background-refresh value back to original value
            objConnection.OLEDBConnection.BackgroundQuery = bBackground
        Next
    
        MsgBox "Finished refreshing all data connections"
    
    End Sub

  5. #5
    Forum Contributor
    Join Date
    02-18-2014
    Location
    hk
    MS-Off Ver
    Excel 365
    Posts
    105

    Re: execute code after finished refresh web query connection

    Thank you Jerry. Now is ok.
    Quote Originally Posted by JBeaucaire View Post
    Then the trick will be to insure the BackGroundQuery=False parameter is set in your actual connection. Can you edit your original connections to set that?

    If not, maybe you can adapt something like this:
    Sub Refresh_All_Data_Connections()
    
        For Each objConnection In ThisWorkbook.Connections
            'Get current background-refresh value
            bBackground = objConnection.OLEDBConnection.BackgroundQuery
    
            'Temporarily disable background-refresh
            objConnection.OLEDBConnection.BackgroundQuery = False
    
            'Refresh this connection
            objConnection.Refresh
    
            'Set background-refresh value back to original value
            objConnection.OLEDBConnection.BackgroundQuery = bBackground
        Next
    
        MsgBox "Finished refreshing all data connections"
    
    End Sub

+ 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. Execute code after OLAP connection has refreshed
    By Polis15 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-11-2014, 09:27 AM
  2. Replies: 2
    Last Post: 09-29-2013, 06:15 AM
  3. Replies: 1
    Last Post: 09-28-2013, 07:11 PM
  4. [SOLVED] Wait until MSQuery Refresh finished
    By ChrisR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-19-2005, 01:05 PM
  5. VBA code to Refresh Connection for Excel Add-in for Analysis Servi
    By Ellis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2005, 04:06 PM

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