Share via


DocumentExtensions.GetVstoObject Method (2007 System)

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

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

Syntax

'Declaration
<ExtensionAttribute> _
Public Shared Function GetVstoObject ( _
    document As _Document _
) As Document
'Usage
Dim document As _Document 
Dim returnValue As Document 

returnValue = document.GetVstoObject()
public static Document GetVstoObject(
    this _Document document
)
[ExtensionAttribute]
public:
static Document^ GetVstoObject(
    _Document^ document
)
public static function GetVstoObject(
    document : _Document
) : Document

Parameters

  • document
    Type: _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.

Return Value

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

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type _Document. 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

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 _Document, which is the parent interface of Document. Therefore, this method extends both types: _Document and Document. Typically, when you reference a Word document, you use a Document.

Limitations in Document-Level Customizations

In a document-level customization, this method has a more limited use than in an application-level add-in. You cannot use it to generate a new extended Microsoft.Office.Tools.Word.Document object for a native document object. You can use this method only to get a Microsoft.Office.Tools.Word.Document object that is in the current customization. For more information, see Getting Extended Objects from Native Office Objects in Document-Level Customizations.

If the native document is not the underlying object of a Microsoft.Office.Tools.Word.Document object in the current customization, this method returns nulla null reference (Nothing in Visual Basic).

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 an add-in project for Word.

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

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

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

DocumentExtensions Class

DocumentExtensions Members

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

Extension Methods (C# Programming Guide)

Extension Methods (Visual Basic)

Change History

Date

History

Reason

July 2008

New method.

SP1 feature change.