Document.VBProject Property (Word)

Office 2013 and later
GitHub-Mark-64px

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the VBProject object for the specified template or document.

expression .VBProject

expression Required. A variable that represents a Document object.

Use this property to gain access to code modules and user forms.

To view the VBProject object in the object browser, you must select the Microsoft Visual Basic for Applications Extensibility check box in the References dialog box (Tools menu) in the Visual Basic Editor.

This example displays the name of the Visual Basic project for the active document.

Set currProj = ActiveDocument.VBProject 
MsgBox currProj.Name

This example adds a standard code module to the active document and renames it "MyModule."

Set newModule = ActiveDocument.VBProject.VBComponents _ 
 .Add(vbext_ct_StdModule) 
NewModule.Name = "MyModule"
Show: