DocumentExtensions.GetVstoObject Method

Definition

Overloads

GetVstoObject(_Document, ApplicationFactory)

Returns a Document host item that extends the functionality of the current Document object in an application-level add-in. Pass the Globals.Factory object in your project to the factory parameter.

GetVstoObject(_Document, Factory)

Returns a Document host item that extends the functionality of the current Document object in a document-level customization. Pass the Globals.Factory object in your project to the factory parameter.

GetVstoObject(_Document, ApplicationFactory)

Returns a Document host item that extends the functionality of the current Document object in an application-level add-in. Pass the Globals.Factory object in your project to the factory parameter.

public static Microsoft.Office.Tools.Word.Document GetVstoObject (this Microsoft.Office.Interop.Word._Document document, Microsoft.Office.Tools.Word.ApplicationFactory factory);

Parameters

document
_Document

The native document object to extend. Do not supply this parameter yourself. When you call this method on a Word document, the runtime supplies this parameter.

factory
ApplicationFactory

An object that provides access to certain features in your application-level add-in. Pass the Globals.Factory object to this parameter.

Returns

A host item that extends the functionality of the current Document object.

Remarks

In an application-level add-in, call this method to extend any document that is open in Word. This method generates a new Microsoft.Office.Tools.Word.Document host item if no such object has already been generated for the Microsoft.Office.Interop.Word.Document object on which you call this method. Subsequent calls to this method on the same Microsoft.Office.Interop.Word.Document object return the same Microsoft.Office.Tools.Word.Document 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 VSTO Add-ins at Run Time.

Note

The document parameter is of type Microsoft.Office.Interop.Word._Document, which is the parent interface of Microsoft.Office.Interop.Word.Document. Therefore, this method extends both types: Microsoft.Office.Interop.Word._Document and Microsoft.Office.Interop.Word.Document. Typically, when you reference a Word document, you use a Microsoft.Office.Interop.Word.Document.

GetVstoObject(_Document, Factory)

Returns a Document host item that extends the functionality of the current Document object in a document-level customization. Pass the Globals.Factory object in your project to the factory parameter.

public static Microsoft.Office.Tools.Word.Document GetVstoObject (this Microsoft.Office.Interop.Word._Document document, Microsoft.Office.Tools.Word.Factory factory);

Parameters

document
_Document

The native document object to extend. Do not supply this parameter yourself. When you call this method on a Word document, the runtime supplies this parameter.

factory
Factory

An object that provides access to certain features in your document-level customization. Pass the Globals.Factory object to this parameter.

Returns

A host item that extends the functionality of the current Document object.

Remarks

In a document-level customization, you can call this method to get a Microsoft.Office.Tools.Word.Document host item that is in the current customization. If the Microsoft.Office.Interop.Word.Document object on which you call this method is not the underlying object of a Microsoft.Office.Tools.Word.Document host item in the current customization, this method returns null.

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 Programming Document-Level Customizations.

Note

The document parameter is of type Microsoft.Office.Interop.Word._Document, which is the parent interface of Microsoft.Office.Interop.Word.Document. Therefore, this method extends both types: Microsoft.Office.Interop.Word._Document and Microsoft.Office.Interop.Word.Document. Typically, when you reference a Word document, you use a Microsoft.Office.Interop.Word.Document.

Applies to