My Blog

Creating a New Excel File

1

In continuation from here

Double click the first button “Create” and paste this code. I will be commenting the code so that can understand what the code does.

Imports Excel = Microsoft.Office.Interop.Excel

Public Class Form1
    '~~> Define your Excel Objects
    Dim xlApp As New Excel.Application
    Dim xlWorkBook As Excel.Workbook

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '~~> Add a New Workbook
        xlWorkBook = xlApp.Workbooks.Add

        '~~> Display Excel
        xlApp.Visible = True
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Close()
    End Sub
End Class

Now when you run the project, your form will launch and when you click on “Create” button, Excel will launch and a new workbook will be created.

  1. NDAYISHIMIYE ISAAC
    NDAYISHIMIYE ISAAC10-21-2013

    Goodmorning sir,
    Just to inform you that I appreciate your web that has halped me in building code that I have spent much time seaching. I cannot have words to use to express my joyfull that I have until i got this web site.
    I hope that you can continue to prepare more greatful tutorials like this.
    Thank you very much.

    ISAAC NDAYISHIMIYE
    FROM BURUNDI
    ndayalp@gmail.com