0

Hello all
I need to solve a equation using excel solver from visual basic 6. i did it manually in excel and recorded tha macro. however when i trid to automate excel using vb, an error message is displayed. it highlights the solverok function and says function not valid.
can someone please tell me whats the problem or how do i automate excel solver using vb6.
any help will be appreciated.
thanks.
shefali.

2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by Shefali
0

thanks for ur response..
here is the code

Dim appExcel As Excel.Application
Dim appBook As Excel.Workbook
Dim appSheet As Excel.Worksheet

Private Sub cmdExcel_Click()
Set appExcel = New Excel.Application
appExcel.Visible = True
Set appBook = appExcel.Workbooks.Add()
ActiveCell.FormulaR1C1 = "a"
Range("A2").Select
ActiveCell.FormulaR1C1 = "b"
Range("A3").Select
ActiveCell.FormulaR1C1 = "c"
Range("A4").Select
ActiveCell.FormulaR1C1 = "u(a,b,c)"
Range("A5").Select
ActiveCell.FormulaR1C1 = "v(a,b,c)"
Range("A6").Select
ActiveCell.FormulaR1C1 = "w(a,b,c)"
Range("B1").Select
ActiveCell.FormulaR1C1 = "1"
Range("B2").Select
ActiveCell.FormulaR1C1 = "1"
Range("B3").Select
ActiveCell.FormulaR1C1 = "1"
Range("B4").Select
ActiveCell.FormulaR1C1 = _
"=18*R[-3]C+14*R[-2]C+16*R[-1]C-(R[-3]C^2+R[-2]C^2+R[-1]C^2)-120"
Range("B5").Select
ActiveCell.FormulaR1C1 = _
"=12*R[-4]C+10*R[-3]C+8*R[-2]C-(R[-4]C^2+R[-3]C^2+R[-2]C^2)-56"
Range("B6").Select
ActiveCell.FormulaR1C1 = _
"=14*R[-5]C+8*R[-4]C+12*R[-3]C-(R[-5]C^2+R[-4]C^2+R[-3]C^2)-74"
Range("A8").Select
ActiveCell.FormulaR1C1 = "sum of squares"
Range("C8").Select
ActiveCell.FormulaR1C1 = "=R[-4]C[-1]^2+R[-3]C[-1]^2+R[-2]C[-1]^2"
SolverOK SetCell:="$C$8", MaxMinVal:=3, ValueOf:="0", ByChange:="$B$1:$B$3"
SolverSolve
End Sub


the solverok and solversolve is creating a problem. it works fine with excel vba but not with vb6. it says function or sub not defined.

kindly help.
thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.