|
|
Title | Evaluate mathematical expressions using Excel |
Keywords | Office, Eexcel, expression, evaluate |
Categories | Office |
|
|
Open an Excel server. Insert the equation into a cell and read the result.
|
|
Private Sub cmdEvaluate_Click()
Dim excel_app As Object
Dim excel_sheet As Object
Set excel_app = CreateObject("Excel.Application")
' Uncomment this line to make Excel visible.
' excel_app.Visible = True
' Check for later versions.
excel_app.Workbooks.Add
If Val(excel_app.Application.Version) >= 8 Then
Set excel_sheet = excel_app.ActiveSheet
Else
Set excel_sheet = excel_app
End If
' Insert the equation.
excel_sheet.Cells(1, 1) = _
"=" & txtExpression.Text
' Get the result.
lblResult.Caption = excel_sheet.Cells(1, 1)
' Comment the rest of the lines to keep
' Excel running so you can see it.
' Close the workbook without saving.
excel_app.ActiveWorkbook.Close False
' Close Excel.
excel_app.Quit
Set excel_sheet = Nothing
Set excel_app = Nothing
End Sub
|
|
|
|
|
|