Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ApplicationFactory.GetVstoObject Method (_Workbook)

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

Namespace:  Microsoft.Office.Tools.Excel
Assemblies:   Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)
  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Workbook GetVstoObject(
	_Workbook workbook
)

Parameters

workbook
Type: Microsoft.Office.Interop.Excel._Workbook

The native workbook object for which to retrieve the extended object. Although this parameter is of type Microsoft.Office.Interop.Excel._Workbook, you typically pass a Microsoft.Office.Interop.Excel.Workbook object to this method.

Return Value

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

Call this method in an application-level add-in to customize any workbook that is open in Excel. This method generates a new 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 Microsoft.Office.Tools.Excel.Workbook object. For more information, see Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time.

NoteNote

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

The following code example creates a Microsoft.Office.Tools.Excel.Workbook host item for the active Excel workbook. To use this code, run it from the ThisAddIn class in an Excel add-in project that targets the .NET Framework 4 or the .NET Framework 4.5.

Workbook vstoWorkbook =
    Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook);

foreach (SmartTag st in vstoWorkbook.VstoSmartTags)
{
    System.Windows.Forms.MessageBox.Show(st.Caption);
}

Show:
© 2015 Microsoft