Dela via


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
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Syntax

'Declaration
Function GetVstoObject ( _
    workbook As _Workbook _
) As Workbook
Workbook GetVstoObject(
    _Workbook workbook
)

Parameters

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.

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

See Also

Reference

ApplicationFactory Interface

GetVstoObject Overload

Microsoft.Office.Tools.Excel Namespace

Other Resources

Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time

Getting Extended Objects from Native Office Objects in Document-Level Customizations