我使用以下代码从 xlwings 模块在 VBA 中调用 RunPython:
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
如何让 SolverAdd 代码等到 RunPython 代码完全完成?