Yaha!!!
this works!
Thank you!
the only problem is that I can not add a reference and execute a function from the reference in the same sub. But this is fine - I can put them into different macros and run sequentially.
Here is what I have:
---- add the reference on SOLVER
Sub ss3()
With ThisWorkbook.VBProject.References
.AddFromFile "C:\ProgramFiles\MicrosoftOffice\Offi ce10\Library\Solver\SOLVER.XLA"
End With
End Sub
----- run solver
Sub ss4()
'set objective function
SolverOk SetCell:="$B$6", MaxMinVal:=2,ValueOf:="0", ByChange:="$B$1:$B$3"
'set constraints
SolverAdd CellRef:="$B$5", Relation:=3, FormulaText:="$G$5"
'set options
SolverOptions MaxTime:=1000, Iterations:=10000, Precision:=0.000001, _
AssumeLinear:=False, StepThru:=False, Estimates:=1, Derivatives:=1, _
SearchOption:=2, IntTolerance:=5, Scaling:=False, Convergence:=0.0001, _
AssumeNonNeg:=True
' Do not display the Solver Results dialog box.
SolverSolve UserFinish:=True
' Finish and keep the final results.
SolverFinish KeepFinal:=1
End Sub