Using VSTA to extend a host with Office

VSTA can be used extend a host to use a new technology, like an Office application, without requiring any changes in the host.  One benefit of this is that the host is now compatible with any technology that can be accessed by an add-in.

One example of this would be to use an Excel spreadsheet to enter data.  We have a simple example of this with ShapeAppCSharp (VSTA v 1 and v 2 samples available here).  The VSTA add-in opens an excel spreadsheet and reads in data for shapes to be added to a drawing.  This allows Excel to be used as a data entry form to automate the host without making any changes to the host. 

To use Office applications in VSTA, add references to the appropriate assemblies.  For VSTA v 1, to add a reference to the Excel application, choose the "Microsoft Excel # Object Library" from the COM tab of the Add References window, it should have a path like %ProgramFiles%\Microsoft Office\OFFICE#\EXCEL.EXE.  This will add the entries "Excel" and "Microsoft.Office.Core" (which can be removed) under references in the Solution Explorer.  When viewed in the Object Browser, the "Excel" entry is identified as Microsoft.Office.Interop.Excel.dll.  For VSTA v 2, the Microsoft.Office.Interop.Excel reference is listed on the .Net tab of the Add References window.  This change is due to the addition of the office libraries into Visual Studio 2008. 


Posted Jan 21 2008, 04:06 PM by Melody
Filed under: , , ,
Copyright Summit Software Company, 2008. All rights reserved.