Display Windows Forms
Excel projects can use Windows forms to gather information and display results. Windows forms are a huge improvement over the forms you can display from Excel VBA.
How to do it
To create a Windows form in Visual Studio .NET for use from Excel, follow these steps:
From the Project menu, choose Add Windows Form. Visual Studio .NET displays the Add New Item dialog box.
Enter a name for the form and click OK. Visual Studio .NET creates a new Windows form class and displays the class in the Designer.
Use the Designer to add controls to the form; then switch to the Code window. Unlike previous versions of Visual Basic, VB.NET describes the entire form in terms of code. The form and control properties are all maintained in the “Windows Form Designer generated code” region of the form’s class.
In order to enable the form to interact with Excel, add the following lines to the generated code (shown in bold ):
Imports Excel = Microsoft.Office.Interop.Excel Public Class SimpleForm Inherits System.Windows.Forms.Form Dim xlCode As OfficeCodeBehind #Region " Windows Form Designer generated code " Public Sub New(ByVal target As OfficeCodeBehind) MyBase.New( ) 'This call is required by the Windows Form Designer. InitializeComponent( ) 'Add any initialization after the InitializeComponent( ) call ' Get the OfficeCodeBehind class that created this form ' (used to return responses to Excel). xlCode = target End Sub ' Remainder of class omitted here...
Within the form’s ...