WorkbookExtensions.GetVstoObject Method (_Workbook, ApplicationFactory)
Returns a Microsoft.Office.Tools.Excel.Workbook host item that extends the functionality of the current Microsoft.Office.Interop.Excel.Workbook object in an application-level add-in. Pass the Globals.Factory object in your project to the factory parameter.
Namespace: Microsoft.Office.Tools.Excel.Extensions
Assembly: Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)
Syntax
'Declaration
<ExtensionAttribute> _
Public Shared Function GetVstoObject ( _
workbook As _Workbook, _
factory As ApplicationFactory _
) As Workbook
public static Workbook GetVstoObject(
this _Workbook workbook,
ApplicationFactory factory
)
Parameters
workbook
Type: Microsoft.Office.Interop.Excel._WorkbookThe 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.
factory
Type: Microsoft.Office.Tools.Excel.ApplicationFactoryAn object that provides access to certain features in your application-level add-in. Pass the Globals.Factory object to this parameter.
Return Value
Type: Microsoft.Office.Tools.Excel.Workbook
A host item that extends the functionality of the current Microsoft.Office.Interop.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).
Remarks
In an application-level add-in, call this method to extend any workbook that is open in Excel. This method generates a new Microsoft.Office.Tools.Excel.Workbook host item if no such object has already been generated for the Microsoft.Office.Interop.Excel.Workbook object on which you call this method. Subsequent calls to this method on the same Microsoft.Office.Interop.Excel.Workbook object return the same Microsoft.Office.Tools.Excel.Workbook instance.
This method is provided for backward compatibility with Office projects that you retarget from the .NET Framework 3.5 to the .NET Framework 4 or the .NET Framework 4.5. In new projects that target the .NET Framework 4 or the .NET Framework 4.5, you should call the GetVstoObject method that is provided by the Globals.Factory object in your project.
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 extends 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.
.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.Extensions Namespace
Other Resources
Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time