|
I
continue to show you
how to use the formulae in Microsoft Excel to perform
arithmetic calculation. In order to integrate Microsoft
Excel into Visual Basic, you need to have Microsoft Excel
installed in your computer. The next step is to click on the
Reference from the project menu and then check on the
Microsoft Excel 11.0 Object Library (If you are using other
versions of MS Office, you may have something like
Microsoft Excel 9.0 Object Library, but it should be OK).
In the program, first of all we
need to create the Excel application by using the
Excel.Application declaration. Then we can enter the values
into the cells using the text boxes. In this example, I use the
Excel formula to compute maximum number from a range of numbers. |
Public xlsAppl As Excel.Application
Private Sub Command1_Click()
Set xlsAppl = Excel.Application
xlsAppl.Workbooks.Add
xlsAppl.Cells(1, 1).Value = Val(Text1)
xlsAppl.Cells(2, 1).Value = Val(Text2)
xlsAppl.Cells(3, 1).Value = Val(Text3)
xlsAppl.Cells(4, 1).Value = Val(Text4)
xlsAppl.Cells(5, 1).Formula = "=Max(A1:A4)"
Label1.Caption = xlsAppl.Cells(5, 1).Value
End Sub
|