【问题标题】:Excel Solver Error while using VBA使用 VBA 时出现 Excel 求解器错误
【发布时间】:2014-03-15 01:20:11
【问题描述】:

我有以下代码,基本上是一个宏记录。录制宏后,我清理了一些发现重复的代码行。当我再次尝试运行此代码时,我得到一个未定义的子或函数错误。我在 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

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    求解器是一个插件,因此在您启用它之前,它不会在您的 vba 代码中工作。我用的是07,所以你点击office按钮->选项->加载项->管理加载项来启用它。不确定其他版本。

    启用插件后,您必须将插件连接到 vba 编辑器。打开 VBA 编辑器 (Alt+F11),然后转到 Tools -> References,然后勾选“SOLVER”并点击 OK。

    查看此 MSDN

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

    【讨论】:

    • 感谢您的浏览和解答。我已在 Solver 中添加并在录制此宏时手动使用它。我还有什么需要做的吗?
    • 嘿,非常感谢。我知道我错过了一些让它运行的基本步骤。
    猜你喜欢
    • 2017-09-13
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 2012-01-20
    • 1970-01-01
    • 2012-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多