9

I mostly write technical documentation. The documents need a lot of cross references. The format of my cross references are always the same:

<heading-number> <space> <heading-text>.

Adding these using the cross reference dialog is a pain. Find the heading, select paragraph-number from the drop down, insert, select paragraph-text from the drop down, insert, go back to the doc, insert the space (and, normally, change the inserted heading-text to Italic).

Is there any more convenient way of doing this? I did look at existing questions about cross-references (and there's a bunch of those) but none seemed to cover this issue.

2 Answers2

4

I have written a macro to comfortably insert cross references, avoiding all the hassle of Microsoft's cross reference dialog that you have described.
It can insert <heading-number>, <heading-text>, your desired <heading-number> <space> <heading-text>, and it can be configured to insert other fields and combinations thereof.

Traveler
  • 370
1

7 years ago and still people fighting with that. Here is my small contribution:

Sub insertRef()
Dim strCode As String
With Dialogs(wdDialogInsertCrossReference)
    .ReferenceType = "Numbered item"
    .ReferenceKind = wdNumberRelativeContext
    .InsertAsHyperlink = True
    .SeparateNumbers = False
    .Show
End With
Selection.TypeBackspace 'trick it selects the complete field
Selection.Copy
Selection.MoveRight Unit:=wdCharacter, Count:=1 ' unselect
Selection.TypeText Text:=" " ' Separate with one space
Selection.PasteAndFormat (wdPasteDefault) ' duplicate the copied field
Selection.TypeBackspace ' Select the duplicated field
strCode = Selection.Fields(1).Code ' get the code from the field
strCode = Replace(strCode, "\r ", "") ' Remove option to have paragraph text
strCode = Replace(strCode, "\w ", "")
Selection.Fields(1).Code.Text = strCode ' Update the text of the ;code text
Selection.Fields.Update ' Update the field to display ยง text
Selection.MoveRight Unit:=wdCharacter, Count:=1 ' Deselect the updated field
Selection.TypeText Text:=" " ' add a space at the end
End Sub

This opens the traditional dialog to insert a cross reference. Insert it as usual, then close the dialog.

The script will

  • select and copy the inserted number,
  • replace the underlying field code so that Paragraph Text is used and then
  • refresh the modified field.

Note that it only works if Paragraph Number is used as the reference type, which ReferenceKind should attempt to set.

Traveler
  • 370
Vince S
  • 11