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 = FalseEnd 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_offEnd Sub
Any help in debugging and resolving this issue would be appreciated.