Excel Application

Enter your search terms Submit search form




 Visual Basic can be integrated with various windows applications such as Microsoft word, Microsoft Excel , Microsoft Access, Microsoft Visual C++, SPSS and etc using ActiveX technologies that were built upon COM, DCOM and OLE.

In this example, I will 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. Finally we can use the Excel formula to calculate the sum of the two numbers.

 .Public xlsAppl As Excel.Application

Private Sub Command1_Click()
Set xlsAppl = Excel.Application
xlsAppl.Cells(1, 1).Value = Val(Text1)
xlsAppl.Cells(2, 1).Value = Val(Text2)
xlsAppl.Cells(3, 1).Formula = "=SUM(A1:A2)"
Label1.Caption = xlsAppl.Cells(3, 1).Value

End Sub






 [Back to VBToday]