How to run solver from a macro

S

Skin Paul

Hi all, Using xl 2004 v.11.3.5 - Mac OS 10.4.10
I am trying to run solver from a macro but not having much luck.
If I select solver from the menu and input the right info and click solve
It works fine. When I run solver via a macro I get a compile error - Sub or
Function not defined.Below is where I"m at. Any pointers to my mistake
please.

Sub Solve()

SolverOk SetCell:="$G$18", MaxMinVal:=3, ValueOf:="510", ByChange:="$C$18"
SolverSolve
End Sub

SolverOk Gets highlighted but I don't know what next to do.
Thanks Paul
 
J

JE McGimpsey

Skin Paul said:
Hi all, Using xl 2004 v.11.3.5 - Mac OS 10.4.10
I am trying to run solver from a macro but not having much luck.
If I select solver from the menu and input the right info and click solve
It works fine. When I run solver via a macro I get a compile error - Sub or
Function not defined.Below is where I"m at. Any pointers to my mistake
please.

XL doesn't have any idea what "SolverOK" means, because it isn't a
built-in function. You need to set a reference to the Solver Add-in.

One way:

In XL, Choose Tools/Solver... Click Close.

In the Visual Basic Editor, click Reset. Choose Tools/References. In the
dialog that opens, check the Checkbox next to Solver. Click OK and save
your workbook.

Now when you open your workbook, XL will load Solver.xla as well, and
your code will compile fine.

As an alternative, you can put an alias from Solver.xla (found in

HD:Applications:Microsoft Office 2004:Office:Add-Ins

into your startup folder (by default

HD:Applications:Microsoft Office 2004:Office:Startup:Excel

but you can specify a different folder in Preferences/General). Then
Solver.xla will open every time you open XL and its functions will
always be available for you to set a reference to.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top