When the above code is executed and run using Start button available at the Microsoft Visual Studio tool bar, it will show the following window −Ĭlicking on the Button would display the following excel sheet.
MsgBox(Err.Description, vbCritical, "Error: " & Err.Number) This is the code I have so far:-Imports Excel Imports Office Public Class Form1 Private xlApp As New Excel.Application Private xlWBook As Excel.Workbook Private Sub Button1Click(ByVal sender As System. ' Make sure Excel is visible and give the user control I am trying to display an excel file in the form. ' Fill C2:C6 with a relative formula (=A2 & " " & B2). ' Fill A2:B6 with an array of values (First and Last Names). ' Create an array to set multiple values at once. ' Format A1:D1 as bold, vertical alignment = center. First, be sure that the Developer tab is visible. ShXL.Cells(1, 4).Value = "Specialization" You can access the VBA environment in Excel 2010 by opening the Microsoft Visual Basic for Applications window. ' Start Excel and get Application object.ĪppXL = CreateObject("Excel.Application") Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ' Add the following code snippet on top of Form1.vb On the COM tab, locate Microsoft Excel Object Library and then click Select.ĭouble click the code window and populate the Click event of Button1, as shown below. Select Add Reference from the Project Menu. Insert a Button control Button1 in the form.Īdd a reference to Microsoft Excel Object Library to your project. Let's start with creating a Window Forms Application by following the following steps in Microsoft Visual Studio: File → New Project → Windows Forms Applicationsįinally, select OK, Microsoft Visual Studio creates your project and displays following Form1.
Creating an Excel Application from VB.Net To avail this interoperability in your application, you need to import the namespace in your Windows Form Application. VB.Net provides support for interoperability between the COM object model of Microsoft Excel 2010 and your application.