You are here: Scripting Techniques > Common Script Operations > Creating index keywords in a script

Creating index keywords in a script

To create top-level index keywords, use the Add method of the Keywords collection:

Keywords.Add "animal"

Keywords.Add "vegetable"

Keywords.Add "mineral"

Keywords created in this manner are not associated with any topics. This is analogous to creating top-level keywords in the Index toolbar.

However, if you use the Keywords collection of the active topic, and not of the project, then the keywords are created and associated with the active topic:

ActiveTopic.Keywords.Add "animal"

ActiveTopic.Keywords.Add "vegetable"

ActiveTopic.Keywords.Add "mineral"

This is analogous to entering keywords in the Index tab of the topic properties pane. Note that you can simplify the script and make it more efficient by assigning the Keywords collection of the ActiveTopic object to a variable:

Dim keys

Set keys = ActiveTopic.Keywords

keys.Add "animal"

keys.Add "vegetable"

keys.Add "mineral"