繁体   English   中英

使用VBA时Excel求解器错误

[英]Excel Solver Error while using VBA

我有以下代码,基本上是录制的宏。 记录宏后,我清除了一些重复的代码行。 当我再次尝试运行此代码时,出现Sub或Function not defined错误。 我检查了有关Stackoverflow的其他Solver 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,所以您单击Office按钮->选项->加载项->管理加载项以启用它。 不确定其他版本。

启用外接程序后,必须将外接程序连接到vba编辑器。 打开VBA编辑器(Alt + F11),然后转到“工具”->“引用”,然后选中“求解器”并单击“确定”。

看到这个MSDN

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM