Simple Way to Connect Microsoft Excel to VB.Net

Submitted by: 
Visitors have accessed this post 329 times.

In this tutorial, I will teach you how to connect Microsoft Excel to VB.Net. This simple method will illustrate how to connect MS Excel to Visual Basic 2015. It will be a big help for an individual to create in their own way that requires this method. Let’s begin.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application in visual basic.
ps1

Step 2

Add a button inside a form.
ps2

Step 3

Double click the button and add the following codes for connecting Microsoft Excel to Visual Basic 2015.

  1. ' it represents the connection of data source
  2. Dim con As OleDb.OleDbConnection
  3. ' declare a variable to store the string path
  4. Dim string_path As String
  5. ' set a string path
  6. string_path = "c:/IT.xls"
  7. 'initailize the oledb connection with the specified connection string
  8. con = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & string_path & " ; " & "Extended Properties=Excel 8.0;")
  9.  
  10. Try
  11. 'opening connection
  12. con.Open()
  13. 'validating the connection
  14. If ConnectionState.Open Then
  15. MsgBox("Connected successfuly")
  16. con.Close()
  17. Else
  18. MsgBox("Unable to connect")
  19. End If
  20. Catch ex As Exception
  21. 'catching errors
  22. MsgBox(ex.Message)
  23. End Try

Output

output


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.