I hope you can follow this. The question is in the end.
I have an Excel 2003 workbook that contains a table of values to be used in DOE (Design of Experiments). This sheet loads (via Workbook.Open
) another workbook and populates the correct fields and then runs the calculation in the second workbook (via Application.Run("backend.xla!calc")
).
In turn, the calculation calls an external .dll
(compiled Fortan) and waits for it to finish (via Declare Sub Calculate Lib "fortran.dll" (args)
). Each run takes 4 minutes. There might be 7 to 21 runs per DOE. In the end key values are pulled back in the first workbook to display the results.
Please help me think of a开发者_Go百科 way to create multiple copies of the second workbook and have them each calculate ( calling the same dll, with different parameters ) at the same time (different excel process) to utlitize a 4-core processor better.
Or maybe some way to directly call an external function asynchronously. I understand that Excel 2003 VBA is single threaded, and an external dll could only be used as singleton (I am not sure).
PS. Feel free to chime in a say that I am pretty much stuck to sequencial style calculations. Its ok, I can take it.
This is quick and dirty, but you should get the idea. The concept is to create entirely new Excel processes and open the workbook from each new process:
Sub MakeNewProcess()
Dim xl As Application
Set xl = New Application
xl.Visible = True
MsgBox "Check task manager and you'll see (at least) two EXCEL.EXE processes"
End Sub
I added the message box because after you click OK on the message box, the xl variable goes out of scope and the new process is automatically killed. If you run your Workbooks.Open
method off of this variable (ie, xl.Workbooks.Open
) it should get you where you want.
精彩评论