WorkbookExtensions.GetVstoObject Method (2007 System)

Visual Studio 2008

Updated: July 2008

Returns a Microsoft.Office.Tools.Excel.Workbook host item that extends the functionality of the current native workbook object.

Namespace:  Microsoft.Office.Tools.Excel.Extensions
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

public static Workbook GetVstoObject(
	this _Workbook workbook


Type: _Workbook

The native workbook object to extend. Do not supply this parameter yourself. When you call this method on an Excel workbook, the runtime supplies this parameter.

Return Value

Type: Microsoft.Office.Tools.Excel.Workbook
A host item that extends the functionality of the current Excel workbook object.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type _Workbook. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Call this method in an application-level add-in to customize any workbook that is open in Excel. This method generates a new extended Microsoft.Office.Tools.Excel.Workbook object if no such object has already been generated. Subsequent calls to this method return the cached instance of the existing Workbook object. For more information, see Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time.


The workbook parameter is of type _Workbook, which is the parent interface of Workbook. Therefore, this method extends both types: _Workbook and Workbook. Typically, when you reference an Excel workbook, you use a Workbook.

Limitations in Document-Level Customizations

In a document-level customization, this method has a more limited use than in an application-level add-in. You cannot use it to generate a new extended Microsoft.Office.Tools.Excel.Workbook object for a native workbook object. You can use this method only to get the Microsoft.Office.Tools.Excel.Workbook object that is in the current customization. For more information, see Getting Extended Objects from Native Office Objects in Document-Level Customizations.

If the native workbook is not the underlying object of a Microsoft.Office.Tools.Excel.Workbook object in the current customization, this method returns null.

The following code example creates a Microsoft.Office.Tools.Excel.Workbook host item for the active Excel workbook. Next, the example checks whether there are any smart tags defined for this workbook. The code displays either the smart tags or a message that none were found. To use this code, run it from the ThisAddIn class in an add-in project for Excel.

Workbook vstoWorkbook = 

StringBuilder sb = new StringBuilder();
if (vstoWorkbook.VstoSmartTags.Count > 0)
    sb.Append("VSTO smart tags found in this workbook:");
    sb.Append("No VSTO smart tags were found in this workbook.");

foreach (SmartTag st in vstoWorkbook.VstoSmartTags)
    sb.Append("\r\n" + st.Caption);




July 2008

New method.

SP1 feature change.

Community Additions