簡體   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