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
Assemblies: Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)
Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)
Syntax
'Declaration
Function GetVstoObject ( _
document As _Document _
) As Document
Document GetVstoObject(
_Document document
)
Parameters
document
Type: _DocumentThe native document object to extend. Although this parameter is of type _Document, you typically pass a Document object to this method.
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 _Document, which is the parent interface of Document. Therefore, this method can accept objects of both types: _Document and Document. Typically, when you reference a Word document, you use a 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 or the .NET Framework 4.5.
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
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.Office.Tools.Word Namespace
Other Resources
Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time