Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to run Solver from Visual Basic?

19 views
Skip to first unread message

Dinosaur51

unread,
Mar 13, 2007, 10:45:23 AM3/13/07
to
I have an Access database application that creates an excel application, an
excel spreadsheet and formats all the data in the appropriate rows and
columns of a worksheet. I would like to launch Solver from the new excel
application, but I cannot run it. I have loaded solver in my references, and
if I look through the addins of the newly created spreadsheet, it's there. Of
course, Access itself does not recognize the solver addin.
Any ideas (including how to generate excel modules from an access program,
then execute the resulting module)? Alternatively, is there a similar addin
for Access (sorry that this is not the forum for that)?
Thanks

Tom Ogilvy

unread,
Mar 13, 2007, 11:24:23 AM3/13/07
to
If you are opening excel from access using automation, then addins are not
loaded automatically to speed things up.

Here is some sample Excel code to add the solver addin and crate a reference
to it:
(written by Dana DeLouise)

Sub SolverInstall()
'// Dana DeLouis
Dim wb As Workbook

On Error Resume Next
' Set a Reference to the workbook that will hold Solver
Set wb = ActiveWorkbook

With wb.VBProject.References
.Remove .Item("SOLVER")
End With

With AddIns("Solver Add-In")
.Installed = False
.Installed = True
wb.VBProject.References.AddFromFile .FullName
End With
End Sub

http://support.microsoft.com/default.aspx?scid=kb;en-us;843304
How to create Visual Basic macros by using Excel Solver in Excel 97

--
Regards,
Tom Ogilvy

Dinosaur51

unread,
Mar 13, 2007, 12:45:23 PM3/13/07
to
I tried this from Access 2003 and got the following problems:
It would not let me access VBProject saying "Programmatic access to
VBProject not trusted."
the statement wb.VBProject.References.Remove.Item("SOLVER") came back
highlighting .Remove and saying "Argument not optional"
the statement app.wb.application solverOK (etc) returns a Function or
subfunction not defined.


I don't seem able to get beyond the compiler (interpreter, or whatever).
Thanks for your help.

Tom Ogilvy

unread,
Mar 13, 2007, 1:36:24 PM3/13/07
to
Accest to the Project is a security setting made by the user. That can't be
overridden with code. YOu can change that in Excel in tools=>Macros=>Security

Trusted Publishers Tab,
at the bottom left, select the two checkboxes.


the code I posted looked like this:

With wb.VBProject.References
.Remove .Item("SOLVER")
End With

Note that there is a space between .Remove and .Item

Dinosaur51

unread,
Mar 13, 2007, 1:54:14 PM3/13/07
to
Oh, the joys of proportional fonts! Thanks for the clarification. In Access,
one of the check boxes (the lower one) is "greyed out" and cannot be
selected. In Excel, I did it, but it does not save the setting and must be
set everytime by the user, in the newly created spreadsheet before the
statement is executed. I suppose being able to change that "programatically",
as they say, would be a breach of security! Once it is selected, it comes
back that "SOLVER" is out of range.
This seemed like such a good idea, too!

Do you know of any REASONABLY priced optimization packages (something less
than the $1500 that Solver.com wants), or a way to hack into solver.dll?

So near, yet so far!
Regards,
Mike

Dinosaur51

unread,
Mar 13, 2007, 1:59:18 PM3/13/07
to
Correction to my previous reply. Once the created spreadsheet was closed, now
new spreadsheets are created with that box checked. The other comment of
subscript out of range still applies, though.
Thx
Mike

Tom Ogilvy

unread,
Mar 13, 2007, 2:41:23 PM3/13/07
to
You can open solver just like a workbook using workbooks.open

that would get it loaded. Whether it would then work properly with code, I
can't say, but it is worth testing.
Solver is a generalized optimizer (therefore probably involved and complex)
- if you have a specific problem, perhaps you can code the algorithm to solve
it.

0 new messages