excel - how to wait for xlwings to complete python code in vba? -
i calling runpython in vba xlwings module following code:
sub portfolio_optimze() runpython ("import quotes; quotes.get_quote()") solveradd cellref:="$h$18:$h$24", relation:=1, formulatext:="$j$18:$j$24" solveradd cellref:="$b$15:$g$15", relation:=4 solverok setcell:="$h$16", maxminval:=1, valueof:=0, bychange:="$b$15:$g$15", _ engine:=1, enginedesc:=" grg nonlinear " solversolve
how make solveradd code wait until runpython code finished?
some info start with: excel on mac allows external processes write cells when excel idle, i.e. while no macros running. that's why runpython
call on mac runs background process kicks in when calling macro finished running.
i suggest 1 of 2 following solutions:
1) program solver part in python, too, example using scipy.optimize
.
2) put solver vba own sub , call python. planned feature next version of xlwings, see here, can work around (assuming wb
workbook):
app = xlwings.application(wkb=wb) app.xl_app.run_vb_macro('solvermacro')
update, since v0.7.1 supported:
>>> solver_macro = wb.macro('solvermacro') >>> solver_macro()
Comments
Post a Comment