Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleEvaluate mathematical expressions using Excel
KeywordsOffice, Eexcel, expression, evaluate
CategoriesOffice
 
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
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated