Reputation: 11
I wonder if it is possible to integrate VBA in my VB.NET application. If so, do you know of any general tutorial that explains how to do this?
Upvotes: 0
Views: 2835
Reputation: 10381
Add the Microsoft Excel Object Library 12.0
(12.0 for Excel 2007, 14.0 for Excel 2010) from the COM tab of the Add Reference
dialog.
The syntax is quite similar, if you are familiar with VBA, you'll pick it up quickly.
Dim wkbk As Workbook
Dim wkst As Worksheet
Set wkbk = Workbooks.Add
Set wkst = wkbk.Worksheets(1)
wkst.Range("A3").Select
ActiveCell.Value = "Put text here"
in VBA, becomes
Imports Excel = Microsoft.Office.Interop.Excel
Dim oExcel As Object
Dim Book As Excel.Workbook
Dim Sheet As Excel.Worksheet
oExcel = CreateObject("Excel.Application")
Book = oExcel.Workbooks.Add()
Sheet = Book.Worksheets(1)
Sheet.Range("A3").Select()
oExcel.ActiveCell.Value = "Put text here"
with the Interop.
Any of the worksheet functions would be available off of the WorksheetFunction
property of the oExcel
object.
Upvotes: 1