Results 1 to 16 of 16

Add Progress Bar to Connection Refresh Query

Threaded View

  1. #1
    Registered User
    Join Date
    12-24-2017
    Location
    Paramus, United States
    MS-Off Ver
    2010
    Posts
    50

    Add Progress Bar to Connection Refresh Query

    I have a macro to refresh 3 Connections and it works well. I tried to add a progress bar run by a user form with a second macro I found. I tried to combine the code from both macros. Currently when I run the combined macro, the progress bar appears at 0% and says it's running task 1, then all 3 Connections are refreshed and the progress bar zooms to 33% and then it runs the same 3 connections again, goes to 66% and the it runs the sames 3 connections and goes to 100%.

    Instead, I want it to run the first connection, say it's running task 1 and go to 33%, run the second connection, say it's running task 2 and go to 66%, run the 3rd connection, say it's running task 3 and go to 100%. I'll show the code for the original refresh macro, the code for the second macro and my failed attempt at a combined macro. Anyone know how make this possible? Thanks

    Original Refresh Macro
    
    Sub RefreshQuery()
    Dim con As WorkbookConnection
    Dim Cname As String
    
    For Each con In ActiveWorkbook.Connections
        If Left(con.Name, 8) = "Query - " Then
        Cname = con.Name
            With ActiveWorkbook.Connections(Cname).OLEDBConnection
                .BackgroundQuery = False  'or true, up to you
                .Refresh
            End With
        End If
    Next
    End Sub
    
    2nd Macro for the Progress Bar
    
    
    Sub TestTheBar()
    
    'Declaring Sub Level Variables
    Dim lngCounter As Long
    Dim lngNumberOfTasks As Long
    
    'Initilaizing Variables
    lngNumberOfTasks = 2
    
    'Calling the ShowProgress sub with ActionNumber = 0, to let the
    'user know we are going to work on the 1st task. Also, set a
    'title for the form
    Call modProgress.ShowProgress( _
                        0, _
                        lngNumberOfTasks, _
                        "Excel is working on Task Number 1", _
                        False, _
                        "Progress Bar Test")
    
    For lngCounter = 1 To lngNumberOfTasks
    
    
        'You can add your code here
    
        'Call the ShowProgress sub each time a task is finished to
        'the user know that X out of Y tasks are over, and that
        'the X+1'th task is in progress.
        Call modProgress.ShowProgress( _
                    lngCounter, _
                    lngNumberOfTasks, _
                    "Excel is working on Task Number " & lngCounter + 1, _
                    False)
    
    Next lngCounter
    
    End Sub
    
    Combined Macro that's not Working
    
    Sub TestTheBar()
    
    'Declaring Sub Level Variables
    Dim lngCounter As Long
    Dim lngNumberOfTasks As Long
    
    'Initilaizing Variables
    lngNumberOfTasks = 3
    
    'Calling the ShowProgress sub with ActionNumber = 0, to let the
    'user know we are going to work on the 1st task. Also, set a
    'title for the form
    Call modProgress.ShowProgress( _
                        0, _
                        lngNumberOfTasks, _
                        "Excel is working on Task Number 1", _
                        False, _
                        "Progress Bar Test")
    
    For lngCounter = 1 To lngNumberOfTasks
        Dim con As WorkbookConnection
    Dim Cname As String
    For Each con In ActiveWorkbook.Connections
        If Left(con.Name, 8) = "Query - " Then
        Cname = con.Name
            With ActiveWorkbook.Connections(Cname).OLEDBConnection
                .BackgroundQuery = False  'or true, up to you
               .Refresh
            End With
        End If
    Next
    
        'You can add your code here
    
        'Call the ShowProgress sub each time a task is finished to
        'the user know that X out of Y tasks are over, and that
        'the X+1'th task is in progress.
        Call modProgress.ShowProgress( _
                    lngCounter, _
                    lngNumberOfTasks, _
                    "Excel is working on Task Number " & lngCounter + 1, _
                    False)
    
    Next lngCounter
    
    End Sub
    Attached Files Attached Files
    Last edited by vibajajo64; 03-06-2018 at 05:04 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need help with Data Connection refresh
    By Roget168 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-06-2017, 08:21 PM
  2. [SOLVED] execute code after finished refresh web query connection
    By mrkhchan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-09-2015, 10:22 AM
  3. Progress indicator or countdown timer while refresh macro is running
    By DanGres in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2014, 09:21 PM
  4. Replies: 2
    Last Post: 09-29-2013, 06:15 AM
  5. Replies: 1
    Last Post: 09-28-2013, 07:11 PM
  6. Query Refresh capturing rows returned to display progress
    By Stewart in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-02-2005, 12:05 PM
  7. Query Refresh-Enable Automatic Refresh Dialogue Box
    By Terri in forum Excel General
    Replies: 0
    Last Post: 05-06-2005, 04:06 PM

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