Excel Sheet
Excel Sheet
VB.Net provides support for interoperability between the COM object model of Microsoft Excel
2010 and your application.
To avail this interoperability in your application, you need to import the namespace
Microsoft.Office.Interop.Excel in your Windows Form Application.
Finally, select OK, Microsoft Visual Studio creates your project and displays following Form1.
https://www.tutorialspoint.com/vb.net/vb.net_excel_sheet.htm 1/4
6/16/23, 4:13 AM VB.Net - Excel Sheet
On the COM tab, locate Microsoft Excel Object Library and then click Select.
Click OK.
Double click the code window and populate the Click event of Button1, as shown below.
https://www.tutorialspoint.com/vb.net/vb.net_excel_sheet.htm 2/4
6/16/23, 4:13 AM VB.Net - Excel Sheet
.Font.Bold = True
.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
End With
' Fill A2:B6 with an array of values (First and Last Names).
shXL.Range("A2", "B6").Value = students
' Fill C2:C6 with a relative formula (=A2 & " " & B2).
raXL = shXL.Range("C2", "C6")
raXL.Formula = "=A2 & "" "" & B2"
' Make sure Excel is visible and give the user control
' of Excel's lifetime.
appXL.Visible = True
appXL.UserControl = True
https://www.tutorialspoint.com/vb.net/vb.net_excel_sheet.htm 3/4
6/16/23, 4:13 AM VB.Net - Excel Sheet
appXL.Quit()
appXL = Nothing
Exit Sub
Err_Handler:
MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft Visual
Studio tool bar, it will show the following window −
Clicking on the Button would display the following excel sheet. You will be asked to save the
workbook.
https://www.tutorialspoint.com/vb.net/vb.net_excel_sheet.htm 4/4