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
Bookmarks