You are here: Scripting Techniques > Common Script Operations > Changing automatic link tags in a script

Changing automatic link tags in a script

In order for a topic to be a destination for a jump or pop-up link, it must have a unique link tag that identifies it. Typically, you do this by enabling automatic link tags for an active paragraph style. For specific instructions, see Adding a Link Tag to a Topic.

Automatic link tags are based on the topic title, but are normalized so that they do not contain any illegal characters (as restricted by the Windows Help compiler):

      Spaces, hyphens, and periods are converted to underscores.

      Letters, numbers, and underscores are unchanged.

      All other characters are removed.

When a script assigned to a paragraph style executes at compile time, the following expression returns the normalized link tag generated by Doc-To-Help:

ActiveTopic.Tag

However, you can change the default behavior by setting the Tag property to a different value. For instance, if you have several documents with like-named topics, you can generate a unique link tag for each topic by appending the document name:

Dim name, pos

name = ActiveTopic.Document.Name

pos = InStr(1, name, ".")

ActiveTopic.Tag = ActiveTopic.Tag + "_" + Left(name, pos 1)

Note the use of the intrinsic VBScript functions InStr and Left to extract the root filename, minus the extension. The variable pos receives the character position of the period in the filename, and the Left function returns a string containing all characters to the left of the period.

To prevent a link tag from being generated, set the Tag property to an empty string:

ActiveTopic.Tag = ""

For more information, see Linking Related Topics.