Creating a New Excel File
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.