This documentation is archived and is not being maintained.

Excel Sample

Visual Studio 2008

The ExcelAuto sample application demonstrates how to use Visual Basic to start Excel, create a workbook from a template, and update cells in a worksheet that then populate graphs in the workbook. The sample also shows how to send the workbook to an e-mail address, either one time or on a regular schedule.

To get samples and instructions for installing them

  • Do one or more of the following:

    • On the Help menu, click Samples.

      The Readme displays information about samples.

    • Visit the Visual Studio 2008 Samples Web site. The most recent versions of samples are available there.

    • Locate samples on the computer on which Visual Studio is installed. By default, samples and a Readme file are installed in drive:\Program Files\Microsoft Visual Studio 9.0\Samples\lcid. For Express editions of Visual Studio, all samples are located online.

For more information, see Visual Studio Samples.

Security noteSecurity Note:

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To run the sample

  1. In Solution Explorer, open ExcelAuto.sln.

  2. Press F5.

This sample requires that your computer have the following applications installed:

  • Visual Studio 2005 with Service Pack 1, or Visual Studio 2008

  • Microsoft Office Excel 2007

This sample consists of a solution named ExcelAuto.sln that contains two projects. ExcelAuto.vbproj is an interactive Windows-based application for automating Excel and setting up a scheduled task. ExcelAutoTask is a console application that contains Excel automation code that is run when the task is scheduled.

When the ExcelAutomation application runs, it opens a form that has buttons for automating Excel.

When you click Load Spreadsheet with Data, ExcelAuto creates a new Excel application. It then creates an Excel workbook from a template and updates the cells with data stored in a file named OrderData.xml. This data represents order status from the Northwind database sample. The spreadsheet is a status report that displays the status of Northwind orders.

You may also want to try the e-mail and task scheduling features in the sample.