Hi,
I have a solution based on two macros, but it requires the users to have the
second macro (ShowGlossaryDefinition) installed. The first macro creates a
field that looks like a hyperlink and hides the text of the "glossary
definition." When the user double-clicks the pseudo-hyperlink created, a
message box containing the glossary definition appears. Try these macros and
see if they do what you want.
Sub CreateGlossaryEntry()
' This macro creates a glossary entry from
' text in the form "entry_name (definition)".
' A field of the form
' {Macrobutton ShowGlossaryDefinition entry_name {Private definition}}
' is created.
' Place the cursor within the entry name before
' running this macro.
Dim linkRange, hideRange As Range
Dim rngStart, rngEnd As Long
Dim entryName As String
Dim myField As Field
With Selection.Range
.MoveEnd unit:=wdWord
rngEnd = .End - 1
.Collapse Direction:=wdCollapseEnd
.MoveStart unit:=wdWord, Count:=-2
rngStart = .Start + 1
End With
Set linkRange = ActiveDocument.Range(Start:=rngStart, End:=rngEnd)
entryName = linkRange.Text
linkRange.Text = ""
With Selection.Find
.ClearFormatting
.Text = "("
.Forward = True
.Wrap = wdFindStop
.Execute
End With
rngStart = Selection.Start
Selection.Collapse Direction:=wdCollapseEnd
With Selection.Find
.ClearFormatting
.Text = ")"
.Forward = True
.Wrap = wdFindStop
.Execute
End With
rngEnd = Selection.End
Selection.Collapse Direction:=wdCollapseEnd
Set hideRange = ActiveDocument.Range(Start:=rngStart, End:=rngEnd)
hideRange.SetRange hideRange.Start + 1, hideRange.End - 1
linkRange.Select
Set myField = ActiveDocument.Fields.Add(Range:=Selection.Range, _
Type:=wdFieldEmpty, PreserveFormatting:=False)
myField.Code.Text = "Macrobutton ShowGlossaryDefinition " & entryName
myField.Select
Selection.Font.Underline = wdUnderlineSingle
Selection.Font.Color = wdColorBlue
Selection.MoveRight unit:=wdCharacter, Count:=1
Selection.MoveLeft unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="PRIVATE " & hideRange.Text
hideRange.SetRange hideRange.Start - 1, hideRange.End + 1
hideRange.Font.Hidden = True
ActiveDocument.Fields(ActiveDocument.Fields.Count - 1). _
ShowCodes = False
Set linkRange = Nothing
Set hideRange = Nothing
Set myField = Nothing
End Sub
Sub ShowGlossaryDefinition()
MsgBox Prompt:=Mid(Selection.Fields(2).Code, 10), _
Title:="Glossary Definition"
End Sub