Templates 对象 (Word)Templates object (Word)

Template 对象的集合, 这些对象代表当前可用的所有模板。A collection of Template objects that represent all the templates that are currently available. 该集合包括打开的模板、附加到打开的文档的模板和在 “模板和加载项” 对话框中加载的共用模板。This collection includes open templates, templates attached to open documents, and global templates loaded in the Templates and Add-ins dialog box.

说明Remarks

使用templates属性可返回templates集合。Use the Templates property to return the Templates collection. 以下示例显示 Templates 集合中每个模板的路径及文件名。The following example displays the path and file name of each template in the Templates collection.

For Each aTemp In Templates 
 MsgBox aTemp.FullName 
Next aTemp

Add方法不适用于Templates集合。The Add method isn't available for the Templates collection. 相反,您可以将模板添加到 模板 集合通过执行下列任一操作︰Instead, you can add a template to the Templates collection by doing any of the following:

  • open方法与Documents集合结合使用, 打开基于模板或模板的文档Using the Open method with the Documents collection to open a document based on a template or a template

  • 结合使用Add方法和Documents集合打开基于模板的新文档Using the Add method with the Documents collection to open a new document based on a template

  • 将 Add方法与Addins集合结合使用以加载全局模板Using the Add method with the Addins collection to load a global template

  • 结合使用AttachedTemplate属性和document对象将模板附加到文档Using the AttachedTemplate property with the Document object to attach a template to a document

使用模板(索引), 其中索引是模板名称或索引号, 返回单个模板对象。Use Templates (Index), where Index is the template name or the index number, to return a single Template object. 以下示例保存 Dot1.dot 模板。The following example saves the Dot1.dot template.

Templates("C:\MSOffice\WinWord\Templates\Dot1.dot").Save

索引号代表模板在Templates集合中的位置。The index number represents the position of the template in the Templates collection. 以下示例显示 Templates 集合中第一个模板的文件名。The following example displays the file name of the first template in the Templates collection.

MsgBox Templates(1).FullName

使用NormalTemplate属性可返回一个代表 Normal 模板的模板对象。Use the NormalTemplate property to return a template object that refers to the Normal template. 使用 AttachedTemplate 返回附加到指定文档的模板的属性。Use the AttachedTemplate property to return the template attached to the specified document.

使用DefaultFilePath属性可确定用户或工作组模板的位置 (即要存储这些模板的文件夹)。Use the DefaultFilePath property to determine the location of user or workgroup templates (that is, the folder where you want to store these templates). 以下示例在 “选项” 对话框中 “文件位置” 选项卡上显示用户模板文件夹。The following example displays the user template folder from the File Locations tab in the Options dialog box.

MsgBox Options.DefaultFilePath(wdUserTemplatePath)

另请参阅See also

Word 对象模型参考Word Object Model Reference

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.