Dictionary 对象

         
多种对象
Dictionaries (Dictionary)

代表一个词典。代表自定义词典的 Dictionary 对象是 Dictionaries 集合中的元素。其他词典对象则由 Languages 集合的各属性(包括 ActiveSpellingDictionaryActiveGrammarDictionaryActiveThesaurusDictionaryActiveHyphenationDictionary 属性)返回。

使用 Dictionary 对象

CustomDictionaries(index) 可返回代表自定义词典的单个 CustomDictionarie 对象,其中 index 是索引序号或词典名称的字符串。下列示例返回集合中的第一个词典。

CustomDictionaries(1)

下列示例返回名为“MyDictionary”的词典。

CustomDictionaries("MyDictionary")

ActiveCustomDictionary 属性可在集合中设置能添加生词的自定义拼写词典。如果给非自定义词典设置该属性,则会导致出错。

Add 方法可在活动自定义词典集合中添加新词典。如果不存在与 FileName 所指定的文件名相对应的文件,则 Word 将创建该文件。下列示例将“MyCustom.dic”添至自定义词典集合中。

CustomDictionaries.Add FileName:="MyCustom.dic"

说明

NamePath 属性可定位任何词典。下列示例显示一个消息框,其中包含每一个词典的全路径。

For Each d in CustomDictionaries
    Msgbox d.Path & Application.PathSeparator & d.Name
Next d

LanguageSpecific 属性可确定是否能用 LanguageID 属性为特定的自定义词典指定专门的语言。如果为词典指定了语言,则只能用于修改指定为该语言格式的文字。

对于已安装校对工具的语言,可用 ActiveGrammarDictionaryActiveHyphenationDictionaryActiveSpellingDictionaryActiveThesaurusDictionary 属性返回相应的 Dictionary 对象。以下示例返回 Word 英文版中所用的活动拼写词典的完整路径。

Set myspell = Languages(wdEnglishUS).ActiveSpellingDictionary
MsgBox mySpell.Path & Application.PathSeparator & mySpell.Name

对于 .lex 文件(内置式校对词典),ReadOnly 属性的返回值为 True;而对于 .dic 文件(自定义拼写词典);其返回值为 False