Share via


WorksheetExtensions.GetVstoObject Method (_Worksheet, ApplicationFactory)

Returns a Microsoft.Office.Tools.Excel.Worksheet host item that extends the functionality of the current Microsoft.Office.Interop.Excel.Worksheet 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 ( _
    worksheet As _Worksheet, _
    factory As ApplicationFactory _
) As Worksheet
public static Worksheet GetVstoObject(
    this _Worksheet worksheet,
    ApplicationFactory factory
)

Parameters

  • worksheet
    Type: Microsoft.Office.Interop.Excel._Worksheet
    The native worksheet object to extend. Do not supply this parameter yourself. When you call this method on an Excel worksheet, the runtime supplies this parameter.

Return Value

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

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type _Worksheet. 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 worksheet that is open in Excel. This method generates a new Microsoft.Office.Tools.Excel.Worksheet host item if no such object has already been generated for the Microsoft.Office.Interop.Excel.Worksheet object on which you call this method. Subsequent calls to this method on the same Microsoft.Office.Interop.Excel.Worksheet object return the same Microsoft.Office.Tools.Excel.Worksheet 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. In new projects that target the .NET Framework 4, 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 worksheet parameter is of type Microsoft.Office.Interop.Excel._Worksheet, which is the parent interface of Microsoft.Office.Interop.Excel.Worksheet. Therefore, this method extends both types: Microsoft.Office.Interop.Excel._Worksheet and Microsoft.Office.Interop.Excel.Worksheet. Typically, when you reference an Excel worksheet, you use a Microsoft.Office.Interop.Excel.Worksheet.

.NET Framework Security

See Also

Reference

WorksheetExtensions Class

GetVstoObject Overload

Microsoft.Office.Tools.Excel.Extensions Namespace

Other Resources

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

Extension Methods (C# Programming Guide)

Extension Methods (Visual Basic)