Excel Solver macro from VB.NET

M

Mr.Doubt

I'm trying to run a Excel macro, which uses SOLVER.XLA Add-In, in
VB.NET application. When the macro is executed I get the following
error message

"Solver: An unexpected internal error occured, or
available memeory was exhausted"

Any suggestions whats causing this error and how to debug it???

Also, I get the following exception message when executing all the
macros from the excel sheet

"Exception from HRESULT: 0x800xxxxx"

I'm not sure about the source of this either.

Can anyone pls help me with these errors?? :)

My code for reference:

Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oBooks As Excel.Workbooks
Dim oSheets As Excel.Sheets
Dim oSheet As Excel.Worksheet
Try

oExcel = CreateObject("Excel.Application")

oBooks = oExcel.Workbooks

oBook =
oBooks.Open("C:\Inetpub\wwwroot\PrePackOptimizer\Data
Source\book2.xls")

oExcel.AddIns.Add("C:\Program Files\Microsoft
Office\OFFICE11\Library\SOLVER\SOLVER.XLA")

oExcel.DisplayAlerts = True

oExcel.Run("Module1.SOLVER")

P.s.: The macro and the SOLVER runs perfectly when run from the EXCEL
file.
 
L

Lucky

this errors seems of memory leaks. when u run the managed code it runs
in its app domain. so the meory alloted by CLR is not enough to run the
code. if is there any way you can process the excel file in a divided
groups of data than you may not get error.

this could be one of the reason.
 
C

Cor Ligthert [MVP]

Mr.Doubt,

Are you sure that the methode were the code is running in is not goin enless
recursive (repeated).

That is hard to debug, because the debugger does not show that standard.

However that is mostly the reason for going out of memory.

Just a thought,

Cor
 
M

Mr.Doubt

Thanx Lucky,

I've found the reason for the error, thanx to
http://www.officehelp.in/ It seems the Solver.XLA needs to be
explicitly opened before it can be used. This is done automatically
when we open the excel manually, but when we use objects, we have to
open it using the following command

oExcel.Run("Solver.xla!Auto_Open")

Once this was done my application started working as
expected...

Regards,
Dinesh
 

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