I have a problem with a VBA in my Excel file.
The Excel file uses a data model as well as several pivot tables.
The VBA is used to refresh all data connections when the file is opened for the first time in the morning.
The code I used for the refresh is as follows:
ThisWorkbook.RefreshAll
Application.CalculateUntilAsyncQueriesDone
If Not Application.CalculationState = xlDone Then
DoEvents
End If
I then stumbled across the issue, that with this code, my pivot tables (which are not relying on the data model but on different connections to different sql servers) do not refresh.
I have disabled background refresh in all pivot tables. Still no difference.
After some research I simply added additional code to refresh the missing connections one by one:
ActiveWorkbook.Connections("Connection Name").Refresh
Now comes the tricky part. When opening the file in the morning VBA still only refreshes the data model and does not touch the pivot connections. When I run the code in debugging mode it seems to execute the pivot refresh code but in fact does not do anything. When i refresh all manually with the refresh all button on the data tab and then run the code in debugging mode it works. I also added the code to a button to check if it works and works fine, also works fine without refreshing manually first. The problem remaining is the refresh when opening.
Looking forward to help! I have no clue what to do next.
Thanks!
2