Templates 集合对象

         
Application
Templates (Template)
多种对象

该对象为 Template 对象组成的集合,这些对象代表所有当前有效的模板。该集合包含了在“工具”菜单中的“模板和加载项”对话框中打开的模板、附加于打开文档的模板和共用模板。

使用 Templates 集合

可用 Templates 属性返回一个 Templates 集合。下例显示 Templates 集合中每一模板的路径及文件名。

For Each aTemp In Templates
    MsgBox aTemp.FullName
Next aTemp

Add 方法在 Templates 集合中无效。可用下列方法之一在 Templates 集合中添加一个模板:

可用 Templates(index) 返回一个 Template 对象,其中 index 为模板名或索引号。下例保存 Dot1.dot 模板。

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

索引号代表模板在 Templates 集合中的位置。下例显示 Templates 集合中第一个模板的路径及文件名。

MsgBox Templates(1).FullName

说明

可用 NormalTemplate 属性返回一个基于 Normal 模板的模板对象。用 AttachedTemplate 属性返回一个附加于指定文档的模板。

可用 DefaultFilePath 属性确定用户或工作组模板(即保存这些模板的文件夹)。下例在“工具”菜单中的“选项”对话框中的“文件位置”选项卡显示用户模板文件夹。

MsgBox Options.DefaultFilePath(wdUserTemplatePath)