H
Holger Fitschen
Hi to all,
I want to use the Excel solver in a VB.Net project.
The macro
Sub Makro1Solver()
Application.Run "Solver.xla!Autpen"
SolverReset
Worksheets(1).Select
Worksheets(1).Range("B9").Select
SolverOk SetCell:="R9C2", MaxMinVal:=3, ValueOf:="0", ByChange:="R8C2"
SolverSolve
End Sub
works fine when starting manually in Excel.
But a message like (sorry it is in german) "Zielzelle muß eine einzelne
Zelle im aktiven Blatt sein." and "Zielzellen müssen sich in der aktiven
Tabelle befinden." appears when I start the macro from my VB.NET
project. My translation for the messages "Goalcell must be a single cell
in an active sheet" and "Goalcells must locate in the active table".
The function in the cell R9C2 is
"=Z(-8)S-Z(-7)S/(Z(-6)S+(Z(-1)S+273.15))-LN(Z(-2)S*(760/1013.25))"
My VB.NET code is
Dim ExApp As New Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ExSheet As Microsoft.Office.Interop.Excel.Worksheet
Try
wb = ExApp.Workbooks.Open("E:\Daten\DD-Rechnung.xls")
ExApp.Run("SOLVER.XLA!Autpen")
ExApp.DisplayAlerts = True
ExApp.Visible = True
wb.Activate()
ExSheet = ExApp.Worksheets("Tabelle1")
ExSheet.Activate()
ExApp.Run("Tabelle1.Makro1Solver()")
Catch ex As COMException
MessageBox.Show("Error accessing Excel: " + ex.ToString())
Catch ex As Exception
MessageBox.Show("Error: " + ex.ToString())
End Try
And I import in vb.net
Imports Microsoft.Office.Interop
Imports System.Runtime.InteropServices
Imports System.Math
A simple macro which wrote some words in the excelsheet/cell works fine,
only the solver makes problems. Also the goalseek macro in excel works
when starting manually but not when starting from vb.net and has no
error messages. It only does nothing...
I searched for several days/weeks but I couldn't find the solution.
Could someone help me please or give me a hint or has an idea how to solve.
Thanks in advance
Holger
I want to use the Excel solver in a VB.Net project.
The macro
Sub Makro1Solver()
Application.Run "Solver.xla!Autpen"
SolverReset
Worksheets(1).Select
Worksheets(1).Range("B9").Select
SolverOk SetCell:="R9C2", MaxMinVal:=3, ValueOf:="0", ByChange:="R8C2"
SolverSolve
End Sub
works fine when starting manually in Excel.
But a message like (sorry it is in german) "Zielzelle muß eine einzelne
Zelle im aktiven Blatt sein." and "Zielzellen müssen sich in der aktiven
Tabelle befinden." appears when I start the macro from my VB.NET
project. My translation for the messages "Goalcell must be a single cell
in an active sheet" and "Goalcells must locate in the active table".
The function in the cell R9C2 is
"=Z(-8)S-Z(-7)S/(Z(-6)S+(Z(-1)S+273.15))-LN(Z(-2)S*(760/1013.25))"
My VB.NET code is
Dim ExApp As New Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ExSheet As Microsoft.Office.Interop.Excel.Worksheet
Try
wb = ExApp.Workbooks.Open("E:\Daten\DD-Rechnung.xls")
ExApp.Run("SOLVER.XLA!Autpen")
ExApp.DisplayAlerts = True
ExApp.Visible = True
wb.Activate()
ExSheet = ExApp.Worksheets("Tabelle1")
ExSheet.Activate()
ExApp.Run("Tabelle1.Makro1Solver()")
Catch ex As COMException
MessageBox.Show("Error accessing Excel: " + ex.ToString())
Catch ex As Exception
MessageBox.Show("Error: " + ex.ToString())
End Try
And I import in vb.net
Imports Microsoft.Office.Interop
Imports System.Runtime.InteropServices
Imports System.Math
A simple macro which wrote some words in the excelsheet/cell works fine,
only the solver makes problems. Also the goalseek macro in excel works
when starting manually but not when starting from vb.net and has no
error messages. It only does nothing...
I searched for several days/weeks but I couldn't find the solution.
Could someone help me please or give me a hint or has an idea how to solve.
Thanks in advance
Holger