Skip to Main Content
Excel 2003 Programming: A Developer's Notebook
book

Excel 2003 Programming: A Developer's Notebook

by Jeff Webb
August 2004
Intermediate to advanced content levelIntermediate to advanced
312 pages
8h 30m
English
O'Reilly Media, Inc.
Content preview from Excel 2003 Programming: A Developer's Notebook

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:

  1. From the Project menu, choose Add Windows Form. Visual Studio .NET displays the Add New Item dialog box.

  2. 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.

  3. 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.

  4. 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...
  5. Within the form’s ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft® Office Excel 2003 Programming Inside Out

Microsoft® Office Excel 2003 Programming Inside Out

Curtis Frye, Wayne S. Freeze, Felicia K. Buckingham
Excel® 2007 VBA Programmer's Reference

Excel® 2007 VBA Programmer's Reference

John Green, Stephen Bullen, Rob Bovey, Michael Alexander
Office 2003 XML

Office 2003 XML

Simon St. Laurent, Mary McRae, Evan Lenz

Publisher Resources

ISBN: 0596007671Supplemental ContentCatalog PageErrata