使用VBA时Excel解算器错误

我有下面的代码,这基本上是一个macroslogging。 在录制macros之后,我清除了一些重复发现的代码行。 当我尝试再次运行此代码时,我得到一个子或函数未定义的错误。 我检查了Stackoverflow上的其他求解VBA问题,我似乎没有做任何错误。 任何人都可以请帮忙? 提前致谢。

Sub Macro2() SolverOk SetCell:="$BF$7", MaxMinVal:=2, ValueOf:=0, ByChange:="$BA$7:$BC$7", Engine:=2, EngineDesc:="Simplex LP" SolverAdd CellRef:="$BA$7", Relation:=4, FormulaText:="integer" SolverAdd CellRef:="$BA$7", Relation:=3, FormulaText:="0" SolverAdd CellRef:="$BB$7", Relation:=4, FormulaText:="integer" SolverAdd CellRef:="$BB$7", Relation:=3, FormulaText:="0" SolverAdd CellRef:="$BC$7", Relation:=3, FormulaText:="0" SolverAdd CellRef:="$BC$7", Relation:=4, FormulaText:="integer" SolverAdd CellRef:="$BE$7", Relation:=3, FormulaText:="0" SolverOk SetCell:="$BF$7", MaxMinVal:=2, ValueOf:=0, ByChange:="$BA$7:$BC$7", Engine:=2, EngineDesc:="Simplex LP" SolverSolve End Sub 

Solver是一个插件,所以它不会在你的VBA代码工作,直到你启用它。 我使用07,所以你点击办公button – >选项 – >加载项 – >pipe理添加到启用它。 不确定其他版本。

一旦启用加载项,您必须将加载项连接到vba编辑器。 打开VBA编辑器(Alt + F11),然后进入工具 – >参考,然后勾选“解决”,然后点击确定。

看到这个MSDN

http://msdn.microsoft.com/en-us/library/office/ff196600%28v=office.15%29.aspx