VBA - My loop keeps excel Not Responding and eventually close

44 views Asked by At

I'm trying to update three OLEDB connections and check if they are refreshing. If not, I want to loop until all are false, with a 5-second wait between loops. When I manually step through the code using F8, it works and eventually finishes. However, in normal execution, it freezes Excel after not responding for 10+ minutes.

Im lost here.

I have tried adding more waits or a msgbox between them, not working.

Sub update()
Dim a As Boolean, b As Boolean, c As Boolean
Dim ci As WorkbookConnection, ca As WorkbookConnection, av As WorkbookConnection

Set ci = ThisWorkbook.Connections("x")
Set ca = ThisWorkbook.Connections("y")
Set av = ThisWorkbook.Connections("z")

ci.Refresh
ca.Refresh
av.Refresh

a = ci.OLEDBConnection.Refreshing
b = ca.OLEDBConnection.Refreshing
c = av.OLEDBConnection.Refreshing


Do Until a = False And b = False And c = False

Application.Wait (Now + TimeValue("00:00:05"))

a = ci.OLEDBConnection.Refreshing
b = ca.OLEDBConnection.Refreshing
c = av.OLEDBConnection.Refreshing

Loop

Calculate

Worksheets("AVANCE").PivotTables("TablaDinĂ¡mica2").PivotCache.Refresh
End Sub
0

There are 0 answers