Answered by:
Excel Solver VBA Problem

I have a problem with programming Excel solver using vba. I have the following micro in a workbook named "Book2.xls":
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 11/8/2005'
SolverOk SetCell:="$H$10", MaxMinVal:=2, ValueOf:="0", ByChange:="$G$10"
SolverAdd CellRef:="$G$10", Relation:=3, FormulaText:="$G$11"
SolverOk SetCell:="$H$10", MaxMinVal:=2, ValueOf:="0", ByChange:="$G$10"
SolverSolve userfinish:=True
End Sub
Macro1 runs fine if I open "Book2.xls" manually and either run it through "Tools\Macro\Macros...\Macro1 > Run " or run it in the VB editor.
I then created another workbook named "Test.xls" with the following code.
Private Sub Workbook_Open()
Workbooks.Open Filename:="C:\test\Book2.xls"
End Sub
With this code, I can open "Test.xls" manually, which then automatically opens "Book2.xls". But when I try to run Macro2 inside "Book2.xls" (either through "Tools\Macro\Macros...\Macro1 > Run " or in the VB editor), the Solver gives me an error "Solver: An unexpected internal error occurred, or available memory was exhausted".
Does someone have any idea of how to fix this problem?
My original intent was to launch an Excel Workbook from within Microsoft Access and automatically run the Excel solver with the data exported from Access (since Access does not have the solver feature). I was given the same error by the solver when I tried to do so.
Question
Answers

Hi,
Since the problem is reported by a thirdparty component: Excel solver, it is out of our support team's boudaries and you would need to contact Excel Solver's support team [http://www.solver.com/suppstdvba.htm] for assistance with this issue.
Perhaps someone else here has run across this issue?
Sorry we can't help out with this one.
brenda (ISV Buddy Team) 
Hi, not sure if it is too late, but I was having the same problem. I was calling the Solver from LabVIEW, and getting the same error. For my case, if I add the:
Application.Run "Solver.xla!Auto_Open"
on the first line of Macro, then I was able to boot the Solver from other app. Maybe it might work...
tetsu
All replies

Hi,
Since the problem is reported by a thirdparty component: Excel solver, it is out of our support team's boudaries and you would need to contact Excel Solver's support team [http://www.solver.com/suppstdvba.htm] for assistance with this issue.
Perhaps someone else here has run across this issue?
Sorry we can't help out with this one.
brenda (ISV Buddy Team) 
Hi, not sure if it is too late, but I was having the same problem. I was calling the Solver from LabVIEW, and getting the same error. For my case, if I add the:
Application.Run "Solver.xla!Auto_Open"
on the first line of Macro, then I was able to boot the Solver from other app. Maybe it might work...
tetsu 

You guys are awesome. I had the exact same problem. I have a database that will open an excel file with solver and some data from the database. The solver is hooked up to the workbook_open command and would always produce that error. I used the application.run line before the solver sub and it worked perfectly.






Yes, the xlam is the extension for addins in Excel 2007... The code in Excel is:
Sub RunSolver()
With Application
.Run "Solver.xlam!SolverReset"
.Run "Solver.xlam!SolverOk", "$B$4", 1, "0", "$E$6E$11"
.Run "Solver.xlam!SolverAdd", "$E$6", 1, "10"
.Run "Solver.xlam!SolverAdd", "$E$6", 3, "0"
.Run "Solver.xlam!SolverAdd", "$E$7", 1, "100"
.Run "Solver.xlam!SolverAdd", "$E$7", 3, "0"
.Run "Solver.xlam!SolverAdd", "$E$8", 1, "1"
.Run "Solver.xlam!SolverAdd", "$E$8", 3, "0"
.Run "Solver.xlam!SolverAdd", "$E$9", 1, "1"
.Run "Solver.xlam!SolverAdd", "$E$9", 3, "0"
.Run "Solver.xlam!SolverAdd", "$E$10", 1, "1"
.Run "Solver.xlam!SolverAdd", "$E$10", 3, "0"
.Run "Solver.xlam!SolverAdd", "$E$11", 1, "1"
.Run "Solver.xlam!SolverAdd", "$E$11", 3, "0"
.Run "Solver.xlam!SolverOk", "$B$4", 1, "0", "$E$6E$11"
.Run "Solver.xlam!SolverOptions", 10000, 10000, 0.000001, False, False, 1, _
1, 1, 0.00001, False, 0.0000001, True
.Run "Solver.xlam!SolverOk", "$B$4", 1, "0", "$E$6E$11"
.Run "Solver.xlam!SolverSolve"
End WithEnd Sub
and I run it in C# using:
Excel.Application xl = null;
Workbook wb = null;
xl = new Excel.Application();
xl.AutomationSecurity =
Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityLow;
xl.Visible = true;
wb = (xl.Workbooks.Open(fileName, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value));
xl.Run("RunSolver", Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value);

I am always getting a problem as solver cant find a solution?How to solve it?Please email me also if possible to grandhi [dot] srivardhan [add] gmail.com
 Edited by Srivardhan G Wednesday, January 25, 2012 5:55 AM
 Edited by danishaniModerator Thursday, January 26, 2012 4:23 AM edit email to avoid spam