Document.GetVstoObject Method (2007 System)

Returns a document host item that extends the functionality of the specified native Word document.

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

Syntax

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

returnValue = Document.GetVstoObject(document)
public static Document GetVstoObject(
    _Document document
)
public:
static Document^ GetVstoObject(
    _Document^ document
)
public static function GetVstoObject(
    document : _Document
) : Document

Parameters

  • document
    Type: _Document

    A native Word document object.

Return Value

Type: Microsoft.Office.Tools.Word.Document
A Visual Studio Tools for Office Word document host item.

Remarks

Calling this method is equivalent to calling the DocumentExtensions.GetVstoObject method. The only difference is that this is a static method (Shared in Visual Basic) that should be called on the Microsoft.Office.Tools.Word.Document type, whereas the DocumentExtensions.GetVstoObject method should be called on a Document object.

Call this method in an application-level add-in to customize any document that is open in Word. This method returns a Microsoft.Office.Tools.Word.Document host item.

This method generates a new extended 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.

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 project, this method has a more limited use than in an application-level add-in. You cannot use it to generate a new Visual Studio Tools for Office Word document for a native Word document. You can use this method to get an existing Visual Studio Tools for Office Word document that was part of the customization project at design time. For more information, see Getting Extended Objects from Native Office Objects in Document-Level Customizations.

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

Examples

The following code example creates a new Microsoft.Office.Tools.Word.Document host item from the active Word document in an application-level add-in. The example uses the new Microsoft.Office.Tools.Word.Document to add 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 = Document.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 = Document.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

Document Class

Document Members

Microsoft.Office.Tools.Word Namespace

DocumentExtensions.GetVstoObject

Other Resources

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

Host Items and Host Controls Overview

Smart Tags Overview

Extension Methods (C# Programming Guide)

Extension Methods (Visual Basic)

Change History

Date

History

Reason

July 2008

New topic.

SP1 feature change.