In continuation from here…
We already covered here how to create the form, set references and place the required buttons. Now we will create a blank workbook.
Double click the first button Create and paste this code. I will be commenting the code so that you 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.