Dear colleagues, I have a macro that loops through and updates reports that include cube formulas (OLAP). The problem is that my VBA code just would not wait for cube functions to refresh and calculate. I spent a good few hours searching web to find that "Application.CalculateUntilAsyncQueriesDone" after the .RefreshAll command should make the code wait untill the refresh is completed. However, when I implemented this in my code, the first file opens up and freezes over (indefinite loop). I would very much appreciate any help here. I am using Excel 2010 and cube formulas in my reports (CUBEMEMBER, CUBESET, CUBEVALUE etc.). Thank you. Vojta
Rich (BB code):
Sub NEW_ForecastUpdate()
Dim TargetFolder As String
Const FILE_EXT As String = "xls*"
Dim FileName As String
Dim wbTemp As Workbook, wsTemp As Worksheet
TargetFolder = "\\grafton.local\grceedfs1\GR-CEE_SharedData\REPORTING FY14-15\test\"
FileName = Dir$(TargetFolder & "*." & FILE_EXT)
Do While Len(FileName) > 0
Set wbTemp = Workbooks.Open(TargetFolder & FileName)
With wbTemp
For Each wsTemp In ActiveWorkbook.Worksheets
wsTemp.Unprotect Password:="usk"
Next wsTemp
.RefreshAll
Application.CalculateUntilAsyncQueriesDone
For Each wsTemp In ActiveWorkbook.Worksheets
wsTemp.Protect Password:="usk", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingColumns:=True
Next wsTemp
.Save
.Close
End With
FileName = Dir$
Loop
End Sub
Last edited by a moderator: