0

I have written a udf returns an array that is inserted at the cell location. the udf can be long running as it reaches out to a rest service to fetch data from a database. so i added a button on my ribbon to do that.

Sub ReCalc(ribbon As IRibbonControl)
    Dim ws As Worksheet
    ActiveWorkbook.ForceFullCalculation = True
    For Each ws In ActiveWorkbook.Worksheets
        ws.Calculate
    Next
    ActiveWorkbook.ForceFullCalculation = False
End Sub

Without the ActiveWorkbook.ForceFullCalculation, worksheet.calculate does not cause the udf to run. If i simply do Application.CalculateFull, it runs the UDF - but ofcourse will also recalculate other workbooks. WHY does this work and above doesnt?

Before the UDF is called, i call this function to turn off automatic calcs and a few other things:

Sub BattenTheHatches(on_off As Boolean, Optional msg As String = "")
    Application.EnableEvents = Not on_off
    Application.DisplayAlerts = Not on_off
    If on_off Then
        Application.Calculation = xlCalculationManual
        Application.Cursor = xlWait
    Else
        Application.Calculation = xlCalculationAutomatic
        Application.Cursor = xlDefault
    End If
    'Application.Volatile Not on_off
    Application.ScreenUpdating = Not on_off
End Sub

Any help in debugging and resolving this issue would be appreciated.

0

1 Answer 1

0

A SWAG: The data gathered by your REST call changes values that causes a recalculation, which causes your REST call to be done again, changing values once more, repeatedly?

Possible "FIX": Do the REST call only once in 15 minutes?
Assuming it completes a single call faster than so.

Also consider https://www.google.com/search?q=excel+calculation+iterations

Related: https://support.microsoft.com/en-us/office/remove-or-allow-a-circular-reference-8540bd0f-6e97-4483-bcf7-1b49cd50d123

3
  • no that's not the problem. the rest call is in code, not in the formula parameters itself. i've traced the problem to when data is inserted in the sheet...after that BattenTheHatches is called once more with FALSE. this then invoked xlCalculationAutomatic. when that happens, the udf gets called again...creating the infinite loop...not sure what to do about this
    – mike01010
    Commented Apr 27 at 6:01
  • The information gathered by the rest call is used in further formulas -> then I'd still wager it is part of the problem.
    – Hannu
    Commented Apr 27 at 6:03
  • It isn't used in further formulas. Plus there isn't a direct link to the formula and the data..I'm writing the data to a matrix/cells offset from the formula (using a timer to get around udfs not being able to do so).
    – mike01010
    Commented Apr 27 at 7:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .