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)
Syntax
'Declaration
Function GetVstoObject ( _
workbook As _Workbook _
) As Workbook
Workbook GetVstoObject(
_Workbook workbook
)
Parameters
workbook
Type: Microsoft.Office.Interop.Excel._WorkbookThe 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.
Remarks
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.
Note
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.
Examples
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.
Dim vstoWorkbook As Workbook = _
Globals.Factory.GetVstoObject(Me.Application.ActiveWorkbook)
For Each st As SmartTag In vstoWorkbook.VstoSmartTags
System.Windows.Forms.MessageBox.Show(st.Caption)
Next
Workbook vstoWorkbook =
Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook);
foreach (SmartTag st in vstoWorkbook.VstoSmartTags)
{
System.Windows.Forms.MessageBox.Show(st.Caption);
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.Office.Tools.Excel Namespace
Other Resources
Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time