How to Read an Excel file in Visual Basic.Net
In this tutorial, I will teach you how to read an excel file in Visual basic.net (VB.Net).
This tutorial can be integrated to your personalized vb.net project.
What is Visual Basic’s purpose?
The third-generation programming language was created to aid developers in the creation of Windows applications. It has a programming environment that allows programmers to write code in.exe or executable files.
They can also utilize it to create in-house front-end solutions for interacting with huge databases. Because the language allows for continuing changes, you can keep coding and revising your work as needed.
However, there are some limits to the Microsoft Visual Basic download.
If you want to make applications that take a long time to process, this software isn’t for you. That implies you won’t be able to use VB to create games or large apps because the system’s graphic interface requires a lot of memory and space.
Furthermore, the language is limited to Microsoft and does not support other operating systems.
So let’s get started:
Step How to Read an Excel file in Visual Basic.Net
- Step 1: First is open the Visual Basic, Select File on the menu, then click New and create a new project.
- Step 2: Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK
- Step 3: Design your form like this just like what I’ve shown you below.
Add a 2 Textbox and a Button
- Step 4: After designing your form. Add a reference to Microsoft Excel 12.0 Object Library
In your project menu click on Project– Add Reference – go to COM tab
Add Microsoft Excel 12.0 Object Library
- Step 5: Then, go to the code page and add the following declarations:
Imports Excel = Microsoft.Office.Interop.Excel Public Class Form1 Dim APP As New Excel.Application Dim worksheet As Excel.Worksheet Dim workbook As Excel.Workbook
- Step 6: Add this following code to Form_Load Event
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
workbook = APP.Workbooks.Open("C:\Users\Clive\Documents\Visual Studio 2008\clive projects\writeandread\writeandread\bin\Debug\sales.xlsx")
worksheet = workbook.Worksheets("sheet1")
End SubStep 7: To get the value from Excel cell to TextBox. Add this following code to the Button Click Event.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click TextBox1.Text = worksheet.Cells(1, 1).Value TextBox2.Text = worksheet.Cells(1, 2).Value End Sub
Step 8: Then finally, add this code to save the Excel file and closes it.
Private Sub Form1_FormClosed(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.FormClosedEventArgs) _ Handles MyBase.FormClosed workbook.Save() workbook.Close() App.Quit() End Sub
- Step 9: Click F5 to run the program.
Frequently Asked Questions
How does this VB.NET project work?
Built with VB.NET WinForms (.NET Framework 4.5+) and SQL Server backend. Standard structure: Form designer to code-behind event handlers to ADO.NET data access layer to SQL Server. Login form for auth. Ready to extend for BSIT capstone scope.
What Visual Studio and SQL Server versions does this VB.NET project require?
Most projects use VB.NET WinForms on .NET Framework 4.5+ with SQL Server 2012 Express or higher. To run: install Visual Studio 2019 / 2022 (Community is free) with the ‘Desktop development with .NET’ workload, install SQL Server Express + SSMS, open the .sln file, build, run.
How do I set up the database for this VB.NET project?
Open SQL Server Management Studio (SSMS) and connect to your SQL Server (e.g. localhost\SQLEXPRESS). Right-click Databases, choose Restore Database OR New Database then import the included .sql script. Update the connection string in App.config (or in code-behind Module) with your server name + credentials. Rebuild and run.
Can I use this VB.NET project for a BSIT capstone or thesis?
Yes, VB.NET is one of the most accepted languages by Philippine BSIT panels. Extend it: add role-based access (admin/staff/customer login redirect), Crystal Reports or RDLC reports, dashboards with Chart control, audit log, multi-branch support. Pair with Chapter 1-5 documentation matching your panel’s rubric.
Why am I getting ‘connection error’ or ‘cannot find SQL Server’?
Three common VB.NET issues: (1) Connection error: SQL Server isn’t running. Open SQL Server Configuration Manager and verify SQL Server (SQLEXPRESS) service is started. (2) Wrong server name in connection string. Try .\SQLEXPRESS, (local)\SQLEXPRESS, or your machine name. (3) Login failed: SQL Server is set to ‘Windows-only’ authentication. Switch to Mixed Mode in SSMS Server Properties, Security.
Where can I find more VB.NET projects with source code?
Browse the VB.NET Projects hub for the full library. For C# WinForms alternatives see C# Projects. For ASP.NET web alternatives see ASP.NET Projects. For BSIT capstone idea lists see 150 Best Capstone Project Ideas.
Inquiries
If you have any questions or suggestions about How to Read an Excel file using Visual Basic.Net please contact me through our contact page or simply leave a comment below.
Download the Code Below
Download How to Read an Excel file using Visual Basic.Net Source code here.
Readers might read also:
- How to Export DataGridView Data to Excel using VB.Net
- How to Create an Excel File Using Visual Basic.Net
- Basic Calculator Using Visual Basic.Net
If you want to get started with a little bit of advance topic in VB.Net you may start your lesson here on how to connect access database to vb.net. Watch the video here below.




This doesn’t work at all if you have Office/Excel 2019.
You are absolutely right. I have tried modifying this (and other) code to read a cell value to no avail.
You are absolutely right but finding a solution that does work is near impossible. I have attempted to modify this (and other) code to get the cell value to no avail.
The above did NOT work for me, but it was a good starting point. Ultimately, I reached a solution, here it is:
Add a reference to Microsoft Excel 12.0 Object Library
In your project menu click on Project– Add Reference – go to COM tab
Add Microsoft Excel 12.0 Object Library
Imports Excel = Microsoft.Office.Interop.Excel
‘ use the Following code in your application
Dim FileName As String
Dim ExcelApp As New Excel.Application
Dim worksheet As Excel.Worksheet
Dim workbook As Excel.Workbook
Dim oRange As Excel.Range
OpenFileDialog1.InitialDirectory = “C:\”
OpenFileDialog1.Filter = “Excel File | *.xlsx”
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
‘ If the Excel File is selected by the user, then do the following….
FileName = OpenFileDialog1.FileName ‘ Set the File Name to a string variable “FileName”
workbook = ExcelApp.Workbooks.Open(FileName) ‘ Open the Excel File
worksheet = workbook.Worksheets(“Sheet1”) ‘ Open “Sheet1”
oRange = worksheet.Range(“A1”) ‘ Set the name of the cell to read/write
Dim str1 As String
str1 = oRange.Value ‘ Read the cell of the selected Sheet1 and the selected Excel File
oRange = worksheet.Range(“E5”) ‘ Set the name of the cell to read/write
oRange.Value = “ABC” ‘ Write a value into cell “A5”
ExcelApp.DisplayAlerts = False ‘ Turn OFF Notifications such as “Do you want to save File?”
ExcelApp.SaveWorkspace() ‘ however, please save the changes to the Excel File
ExcelApp.Quit() ‘ Important: Release the resources used by this Application
End If
Thanks for the feedback.