Word: Insert Next Field Reference
Here's a macro that will look for the next field, then insert it as a reference. It works for Tables and Figures.
For instance, say you have a sentence like:
For results, refer to ____ below:
Table 3 Results
Day
1
Result
30 mg
Comment
Pass
To add the reference to Table 3, simply position the cursor on ____ and run the macro. This will automatically find the next field (i.e. Table 3), work out that it's a Table or Figure (or any other sequence), and add this as a reference.
Note this does not work on headings. There are other macros that can be found that match numbered headings to fields.
Sub InsertNextFieldReference()
'
' Inserts the next Table/Figure as a reference to make referencing a breeze
' Edward Chan (c) 2018
'
'
Dim currentPosition As Range
Set currentPosition = Selection.Range 'pick up current cursor position
Dim aField As Field
Set aField = Selection.NextField
Debug.Print aField.Result
Debug.Print aField.Code.Text
afieldtext = Split(aField.Code.Text, " ")
Dim aFieldType As String
aFieldType = afieldtext(2) ' The second word in the field code is the sequence type (e.g. Table or Figure)
currentPosition.Select ' Go back to original location
Selection.InsertCrossReference ReferenceType:=aFieldType, ReferenceKind:= _
wdOnlyLabelAndNumber, ReferenceItem:=aField.Result, InsertAsHyperlink:=True, _
IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
End Sub