Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic Load Solver.xla

Status
Not open for further replies.

yliew

Civil/Environmental
Jan 16, 2002
19
AU
Dear All,

I realised that not all Excel comes with Solver.xla "checked" as default (in Visual Basic Module). As a result, some of the macro I wrote which uses solver will not work in those computers unless the user manually select the solver check box.

Hence, I am wondering if anyone could teach me how to write a script which load Solver.xla automatically as part of a macro.

Many thanks!

EK
 
Replies continue below

Recommended for you

You should be able to load it through:
Code:
AddIns("Solver Add-In").Installed = True
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Dear Dsi,

I tried your method by uncheck the solver and run the line which you recommended but it does not work. Do I need to specify the path to the library etc?

Thanks again.

EK
 
It seems to work OK, both in the explicit and implicit versions:

AddIns("solver add-in").Installed = True
or
AddIns.Add("solver.xla").Installed = True

Note that the spelling and punctuation must be exact. The explicit version does require you to know the actual file name, which, for Solver, is not too hard to figure out.

TTFN
 
Dear TTFN,

I tried the following code without checking the SOLVER.xla box manually and it won't work. Could you see anything wrong in the code?

The error message is:

"Compiled Error"
"Sub or Function Not Defined"

If I checked the solver.xla manually, it works fine.

Thanks again.

_____________________________

Sub Solver300()

' Solver used to solve stud with 300 spacing
'

AddIns("solver add-in").Installed = True

SolverReset
SolverOptions Iterations:=10000, Precision:=0.01
SolverOk SetCell:="$G$16", MaxMinVal:=3, ValueOf:="0", ByChange:= _
"$B$15,$B$17,$B$18,$B$19,$B$20,$B$21,$B$22,$B$23"

SolverAdd CellRef:="$G$17", Relation:=2, FormulaText:="0"
SolverAdd CellRef:="$G$18", Relation:=2, FormulaText:="0"
SolverAdd CellRef:="$G$19", Relation:=2, FormulaText:="0"
SolverAdd CellRef:="$G$20", Relation:=2, FormulaText:="0"
SolverAdd CellRef:="$G$21", Relation:=2, FormulaText:="0"
SolverAdd CellRef:="$G$22", Relation:=2, FormulaText:="0"
SolverAdd CellRef:="$G$23", Relation:=2, FormulaText:="0"

SolverSolve UserFinish = False

End Sub

___________________

 
sorry, I can't get the code to run either way, so there's something missing, like some sort of register command that registers the subcalls in the library?

TTFN
 
Sorry, you must be talking about the References Solver box. That has to be checked, since that's the only way the VBA knows what the subcalls are. I don't think there's any way around that.

TTFN
 
Another way is to check SOLVER library in Tools-preferences in VBA project. When it's checked the solver add-in will be activated automatically every time you open spreadsheet. (Assuming it's been installed during MS Office installation).
 
Thanks IRstuff and yakpol. I have tried yakpol's method and it works.... but only with office installed in the same directory and drive. I guess that is good enough considering most people install their office in "c:\program files" except those with dual boot.

Anyway, thanks for all your help and time.

EK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top