Share via


ApplicationFactory.GetVstoObject Method

Returns a Microsoft.Office.Tools.Word.Document host item that extends the functionality of the specified native document object.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

'Declaration
Function GetVstoObject ( _
    document As _Document _
) As Document
Document GetVstoObject(
    _Document document
)

Parameters

Return Value

Type: Microsoft.Office.Tools.Word.Document
A host item that extends the functionality of the native document object.

Remarks

Call this method in an application-level add-in to customize any document that is open in Word. This method generates a new Microsoft.Office.Tools.Word.Document object if no such object has already been generated. Subsequent calls to this method return the cached instance of the existing Microsoft.Office.Tools.Word.Document object. For more information, see Extending Word Documents and Excel Workbooks in Application-Level 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 can accept objects of 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.

Examples

The following code example creates a Microsoft.Office.Tools.Word.Document host item for the active Word document. The example then adds a PlainTextContentControl to the document. To use this code, run it from the ThisAddIn class in a Word add-in project that targets the .NET Framework 4.

Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)

vstoDoc.Paragraphs.Last.Range.InsertParagraphAfter()
Dim myPlainTextControl As PlainTextContentControl = _
    vstoDoc.Controls.AddPlainTextContentControl( _
    vstoDoc.Paragraphs.Last.Range, _
    "myPlainTextControl")
myPlainTextControl.PlaceholderText = "Insert first name"
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);

vstoDoc.Paragraphs.Last.Range.InsertParagraphAfter();
PlainTextContentControl myPlainTextControl =
    vstoDoc.Controls.AddPlainTextContentControl(
    vstoDoc.Paragraphs.Last.Range,
    "myPlainTextControl");
myPlainTextControl.PlaceholderText = "Insert first name";

.NET Framework Security

See Also

Reference

ApplicationFactory Interface

Microsoft.Office.Tools.Word 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