jeudi 2 avril 2015

VBA and dlls in C: Strategy for more responsive and controllable Excel performance?

I have an Excel workbook that another (3rd party. Not under my control) application pushes data onto. I have written various VBA functions that are triggered via an Worksheet.Change event when certain cells change.


Some of those functions call functions in a dll that do some heavy computational work and return values to the VBA a few seconds later.


That is of course much better than doing it in VBA but the control is not perfect for three reasons.




  • I hope to scale the solution so I can use ten-twenty worksheets in one workbook at the same time (the 3rd party program that pushes the data to the workbook isn´t flexible enough to push to different workbooks). While the calculations doesn´t take much time they WILL try to fire from different worksheets while the VBA is waiting for the result from the dll on another.




  • And as a consequence of the above: As VBA is single threaded and it waits for the code in the dll to finish, only one calculation in the dll is done at the time, making the number of available cores immaterial.




  • And I would actually like some of the dll calculations to update the relevant cells on the worksheet after a delay. If the delay is done either directly in the VBA or as part of the dll, the time the VBA is unavaliable to "service" other changes in the workbook only gets worse.




So my question is this: So instead of VBA waiting for the result of an calculation is it possible to have the dll address the cells directly? So instead of calling a dll function like this


range("A1") = afunction(range("A2"),range("A3"),range("A4"))


I would just activate funcion and give the cell as a paramteter


afunction(range("A2"),range("A3"),range("A4"),A1)


thus freeing up the VBA to do other things and let the dll post the results on its own when done (or after a delay defined in the dll)


The functions in the dll is written in C and is purely "closed" computational of nature.


Aucun commentaire:

Enregistrer un commentaire