Evaluate mathematical expressions using Excel's Evaluate function

Started by nandagopal, Nov 06, 2008, 04:09 PM

Previous topic - Next topic

nandagopal

A previous example shows how to evaluate an expression by writing it into an Excel cell. Kent Finkle points out that you can use Excel's Evaluate function without even creating a worksheet.


Private Sub cmdEvaluate_Click()
Dim excel_app As Object

    Set excel_app = CreateObject("Excel.Application")

    ' Uncomment this line to make Excel visible.
'    excel_app.Visible = True

    ' Get the result.
    lblResult.Caption = _
        excel_app.Evaluate(txtExpression.Text)

    ' Comment the rest of the lines to keep
    ' Excel running so you can see it.

    ' Close Excel.
    excel_app.Quit
    Set excel_app = Nothing
End Sub