Excel Workbook Project Template
Applies to |
---|
The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office. Project type
Microsoft Office version
For more information, see Features Available by Application and Project Type. |
The Excel Workbook project template in Visual Basic and Visual C# provides the groundwork for solutions that are based on new or existing Microsoft Office Excel workbooks. There are different project templates for Excel 2003 workbooks and Excel 2007 workbooks. The project templates automatically add the necessary assembly references, files, and generated code to use as a starting point for your solution.
Note
By default, some of the files and references in the following list are hidden. To see them, click Show All Files on the Solution Explorer toolbar. Additionally, there are some files and references not in the following list that are common to many Visual Studio project templates.
Files
Visual Studio Tools for Office generates the following visible files in Excel 2003 and Excel 2007 workbook projects:
Workbook Name.xls - Represents the Excel workbook in the project. Contains all of the worksheets and charts.
Sheet1 (.vb file for Visual Basic or .cs file for Visual C#) - A worksheet that provides the design surface and the code for the first worksheet in the workbook. For more information, see Worksheet Host Item.
Sheet2 (.vb file for Visual Basic or .cs file for Visual C#) - A worksheet that provides the design surface and the code for the second worksheet in the workbook.
Sheet3 (.vb file for Visual Basic or .cs file for Visual C#) - A worksheet that provides the design surface and the code for the third worksheet in the workbook.
ThisWorkbook (.vb file for Visual Basic or .cs file for Visual C#) - Contains the design surface and the code for workbook-level customizations. For more information, see Workbook Host Item.
Note
You cannot add additional classes to the code file behind a document, workbook, or worksheet. You must add new files to your project to contain any classes you want to write.
Visual Studio Tools for Office also generates the following additional file when you build an Excel 2007 workbook project:
- Project Name_TemporaryKey.pfx - A temporary certificate that can be used to sign the application and deployment manifests for the project during development. For more information, see Granting Trust to Office Solutions (2007 System) and Security in Office Solutions (2007 System).
Hidden Files
Visual Studio Tools for Office generates several hidden files. Do not modify these files manually; they are regenerated when changes are made to the project and they do not retain manual modifications.
Visual Studio Tools for Office generates the following hidden files:
ThisWorkbook.Designer.xml - A read-only declarative representation of the programmable objects in the workbook.
ThisWorkbook.Designer (.vb file or .cs file) - A read-only code file that provides helper implementations for objects in the workbook, including code to instantiate objects correctly.
Sheetn.Designer.xml - A read-only declarative representation of the programmable objects in the worksheet.
Sheetn.Designer (.vb file or .cs file) - A read-only code file that provides helper implementations for objects in the worksheet, including code to instantiate objects correctly.
Workbook Name.Designer.xml - A read-only declarative representation of programmable objects such as custom controls that are not a part of Visual Studio Tools for Office by default. This file is generated when you add a custom control to a worksheet in the workbook.
Workbook Name.Designer (.vb file or .cs file) - A read-only code file that provides helper implementations for custom controls. This file is generated when you add a custom control to a worksheet in the workbook.
Template Code
The following event handlers are included in the project template code files. For more information, see Visual Studio Tools for Office Project Events.
Startup Event Handlers
These event handlers handle the Workbook.Startup and Worksheet.Startup events. These events are raised for each of the worksheets and the workbook after the solution is running and all the initialization code in the assembly has run. Use these event handlers to run code that initializes your solution.
The Startup event handlers in a workbook solution are called in this order:
ThisWorkbook_Startup.
Sheet1_Startup.
Sheet2_Startup.
Sheet3_Startup.
Other sheets in order.
The order is determined when the project is compiled. If the user rearranges the sheets at run time, it does not change the order that the events are raised the next time the workbook is opened.
Shutdown Event Handlers
These event handlers handle the Workbook.Shutdown and Worksheet.Shutdown events. These events are raised for each of the worksheets and the workbook when the application domain that your code is loaded in is about to unload.
The Shutdown event handlers in a workbook solution are called in this order:
ThisWorkbook_Shutdown.
Sheet1_Shutdown.
Sheet2_Shutdown.
Sheet3_Shutdown.
Other sheets in order.
References
Visual Studio Tools for Office automatically creates a set of assembly references in Excel workbook projects. These references include the following assemblies:
Assemblies in the Visual Studio Tools for Office runtime. For more information about these assemblies, see Visual Studio Tools for Office Runtime Overview.
Primary interop assemblies for shared Microsoft Office components and for Excel. For more information, see Office Primary Interop Assemblies.
.NET Framework assemblies that are used when you develop Visual Studio Tools for Office solutions.
See Also
Tasks
How to: Create Visual Studio Tools for Office Projects
Concepts
Assemblies in Office Solutions Overview