Results 1 to 5 of 5

Thread: DoEvents ActiveWorkbook.RefreshAll Run second part of Macro Once Complete

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    VBAX Contributor
    Joined
    Dec 2009
    Location
    Sevastopol
    Posts
    150
    Location
    Ok, try such tweaking of the code of your workbook:

    1. Copy all code shown in post#2 into ThisWorkbook module of your workbook.
    2. Copy into MacroPart1 the top part of your MPMDataRefresh code up to the line with ActiveWorkbook.RefreshAll .
    3. Copy into MacroPart2 the rest lines of MPMDataRefresh code which are below the line with ActiveWorkbook.RefreshAll

    As the result your code of MPMDataRefresh macro now are in two parts, i.e. in MacroPart1 and MacroPart2 macros, and MPMDataRefresh subroutine is not required.

    Below is template for MacroPart1 and MacroPart2:
    
    ' First stuff with RefreshAll at the end of macro
    Sub MacroPart1()
      ' Part of the code copied from your MPMDataRefresh
      ' from top up to the line with ActiveWorkbook.RefreshAll
    End Sub
    
    ' This macro will be called from QT_AfterRefresh code
    Sub MacroPart2()
      ' The rest lines of MPMDataRefresh code
      ' which are below the line with ActiveWorkbook.RefreshAll
    End Sub
    It’s assumed that only one query is in your workbook.
    For adjusting replace this line of Workbook_Open code: Set QT = Sheet1.QueryTables(1)
    by that one: Set QT = Sheets("YourSheetNameWithQuery").QueryTables(1)
    Instead of ""YourSheetNameWithQuery"" apply the appropriate sheet name where the query is.

    If more than one queries are used or if you stuck then could you provide workbook example with dummy data?

    Vladimir
    Last edited by ZVI; 02-25-2010 at 07:41 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •