Create an Excel 2007 file in VB.NET 2005

By: Issac Emailed: 1604 times Printed: 2075 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

Excel file can be automated or worked upon by Auomation to Excel 2007,It can be done in two ways through Excel Object Model and using Microsoft Jet Engine to connect to Excel, through this we can achieve creating new wokbook add data to it or create charts in it, For creating an Excel 2007 worksheet in VB.NET 2005 , you have to add the Microsoft Excel 12.0 Object Library in you project.

From the following pictures to show how to add Excel reference library in your project.

1. Create a new project and add a button to the Form.

Select reference dialouge from Project menu 


Select Microsoft Excel 12.0 Object Library and click OK button 

Now you can start coding to create a new Excel file.

Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object,_
	 ByVal e As System.EventArgs) Handles Button1.Click

        Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim misValue As Object = System.Reflection.Missing.Value

        xlApp = New Excel.ApplicationClass
        xlWorkBook = xlApp.Workbooks.Add(misValue)
        xlWorkSheet = xlWorkBook.Sheets("sheet1")
        xlWorkSheet.Cells(1, 1) = ""



        MsgBox("Excel file created , you can find the file c:\")
    End Sub

    Private Sub releaseObject(ByVal obj As Object)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        End Try
    End Sub

End Class

In the code, Imports Excel = Microsoft.Office.Interop.Excel - we assign the excel reference to a variable called Excel. 
When you execute this program, the file created in the c:\ of your system. Home | All Tutorials | Latest Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


1. View Comment

Nice post. Can you tell me how can i add shape in Excel 2007 through (Visual Studio 2010) in a merge cell. I merged 4 cell (Range B2:B3 - B2-C2 C2:C3) now i want to insert shape in the merge cell.

View Tutorial          By: Sonia at 2012-06-08 04:57:18

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by Issac
Save/Write/Read image file from/to a database using Java program
How to modify the objects using java classes
Java program for Cloning
Java program for changeable wrapper class
A tutorial on Chat Server and Chat Client in
Chat Server in
Chat client in
How to open and read an XML file in
How to create an XML file in
XML and
How to create an XML file in VB.NET using Dataset
Multi Threaded Client Socket Programming in
Multi Threaded Server Socket Programming in
Multi threaded Socket Programming in
Client Socket Program sample in

More Tutorials in
Scope in
Unstructured Exception Handling in
Structured Exception Handling in
Creating Sub Procedures in
Creating Functions in
Passing a Variable Number of Arguments to Procedures in
Specifying Optional Arguments with default values in Procedures in
Preserving a Variable's Values between Procedure Calls in
Procedure Delegates in
Properties in
Understanding Scope in
Using Resume Next and Resume Line in
Using On Error GoTo 0 in
Getting an Exception's Number and Description in
Raising an Exception Intentionally in

More Latest News
Most Viewed Articles (in )
How to export from database to excel using
Your first VB.NET Crystal Reports - A step by step guide
How To Connect To A MySql Database in
How to export from DataGridView to excel using
Visual Basic Statements
Insert cell data in an Excel file using OLEDB in
Creating Tree Views in Code using
What's New in VB .NET? A comparison of VB vs
Assemblies, Solutions and Projects in VB .NET
How to Open and Edit Cells in an Excel 2007 file in VB.NET
Client Socket Program sample in
Structured Exception Handling in
Changes in Controls from VB6 to
Using Select Case in
For Loop in
Most Emailed Articles (in
For Loop in
For Each…Next Loop in
How to export from DataGridView to excel using
Passing a Variable Number of Arguments to Procedures in
Raising an Exception Intentionally in
“Using If with And” and Comparing two integers using If
What is .NET Framework and the Common Language Runtime?
Data types in
String equals, Copy to & Copy to in
Handling Timer Events - and Creating an Alarm Clock in
Properties in
The Select Case statement in
File Extensions Used in VB .NET
Sub Procedures and Functions in
String.Contains (), compare, clone in