This documentation is archived and is not being maintained.

Document.HasVstoObject Method (2007 System)

Visual Studio 2008

Updated: July 2008

Returns a value that indicates whether a Word Microsoft.Office.Tools.Word.Document host item has been created for 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)

public static bool HasVstoObject(
	_Document document


Type: _Document

A native Word document object.

Return Value

Type: System.Boolean
true if a document host item has been created for the specified native Word document; otherwise, false.

Calling this method is equivalent to calling the DocumentExtensions.HasVstoObject 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.HasVstoObject method should be called on a Document object.

For example, you can call this method in an application-level add-in and if this method returns true, you can test for the existence of managed controls that you want to persist before closing or saving the Word document.

You can also use this method in a document-level customization.


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.

The following code example checks whether the current document has an extended Visual Studio Tools for Office object and, if so, it gets the object. If managed controls exist in the document, the example displays a message that the controls will not be persisted when saving the document. This code example uses the event handler for the DocumentBeforeClose event to perform the check. To use this code, run it from the ThisAddIn class in an add-in project for Word.

void Application_DocumentBeforeClose(
    Microsoft.Office.Interop.Word.Document Doc, ref bool Cancel)
    if (Document.HasVstoObject(Doc) == true)
        Document vstoDoc = Document.GetVstoObject(
        if (vstoDoc.Controls.Count > 0)
                "The VSTO controls are not persisted when you"
                + " save this document.",
                "Controls Persistence",




July 2008

New topic.

SP1 feature change.