On reflection, I suspect a table of contents would be better suited to this,
which would give you your hyperlinks to the TC fields in the document. The
only problem is in the naming of the Hyperlinks - though the numbering is
easily handled with a docvariable
If you run the first macro - InsertTCField
it will set the initial variable value to 1 (you can reset that number with
the second macro ResetVarTC) then insert a TOC entry field with the text
"Location n" where n is the incrementing number from the docvariable field
and "Location " the fixed text.
Each time you run the macro you will get an incremented TOC entry field.
The final macro will insert the hyperlinks (the table of contents) at the
start of the document
Sub InsertTCField()
Dim oVars As Variables
Dim sNum As Long
Set oVars = ActiveDocument.Variables
Start:
On Error GoTo NoVar
sNum = oVars("varTC").Value
Selection.Fields.Add Selection.Range, wdFieldTOCEntry, _
Chr(34) & "Location " & sNum & Chr(34), False
oVars("varTC").Value = oVars("varTC").Value + 1
Exit Sub
NoVar:
oVars("varTC").Value = 1
GoTo Start
End Sub
Sub ResetVarTC()
Dim oVars As Variables
Set oVars = ActiveDocument.Variables
oVars("varTC").Value = InputBox("Enter new start number", _
"TOC Variable Number", oVars("varTC").Value)
End Sub
Sub InsertTOCField()
With Selection
.HomeKey wdStory
With .Fields
.Add Selection.Range, wdFieldTOC, "\f \n \h \z", False
.Update
End With
.TypeParagraph
End With
With ActiveWindow.View
.ShowFieldCodes = False
.ShowHiddenText = False
End With
End Sub
http://www.gmayor.com/installing_macro.htm