Forum

Excel VBA code to R...
 
Notifications
Clear all

Excel VBA code to RefreshAll, Save and Close

2 Posts
1 Users
0 Reactions
153 Views
(@Anonymous)
Posts: 0
New Member Guest
 

I'm using the code below, but my Do While Application.CalculationState <> xlDone is not working correctly. The macro tries to save the file before the Refresh All is completed.

Please provide a solution.

Sub RefreshAllConnections()
' Refresh all data connections in the workbook
ThisWorkbook.RefreshAll

' Wait for the refresh to complete before continuing
Do While Application.CalculationState <> xlDone
DoEvents
Loop

' Save the workbook after the refresh is complete
ThisWorkbook.Save

' Close the workbook
ThisWorkbook.Close SaveChanges:=False
End Sub

 
Posted : 28/08/2024 9:07 am
(@Anonymous)
Posts: 0
New Member Guest
 

I unchecked "Enable background refresh" for all queries and that solved the problem.

 
Posted : 30/08/2024 10:53 am
Share: