![]() |
|
|||||||
|
|
Thread Tools | Display Modes |
|
#11
|
||||
|
||||
|
Yep, that was a pretty big oversight on my behalf. Try this version - again, on a copy of your good document.
Code:
Sub RestrictXRefsSelection()
Dim aFld As Field, aRngXRef As Range, sWord As String, aRngAnchor As Range, sBkmk As String
Dim arrCode() As String, aRng As Range, aRngBk As Range
Set aRng = Selection.Range
For Each aFld In aRng.Fields
If aFld.Type = wdFieldRef Then
Set aRngXRef = aFld.Result
sWord = LCase(Trim(aRngXRef.Words(1)))
If sWord = "table" Or sWord = "figure" Then
arrCode = Split(Trim(aFld.Code), " ")
sBkmk = arrCode(1)
If ActiveDocument.Bookmarks.Exists(sBkmk) Then
Set aRngAnchor = ActiveDocument.Bookmarks(sBkmk).Range
If InStr(LCase(aRngAnchor.Text), sWord) > 0 Then
aRngAnchor.MoveStart Unit:=wdCharacter, Count:=Len(sWord) + 1
ActiveDocument.Bookmarks.Add Name:=sBkmk, Range:=aRngAnchor
End If
aFld.Update
aFld.Select
If Trim(LCase(aRngXRef.Words.First.Previous.Text)) <> sWord Then
Selection.Range.InsertBefore sWord & " ("
Selection.Range.InsertAfter ")"
End If
End If
End If
End If
Next aFld
aRng.Select
End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
| Tags |
| vba code, vba editor, word 19 |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to update Exhibits and related cross-references numbers automatically? | Surendra Yadav | Word | 4 | 10-30-2018 03:02 PM |
How to convert text that is enclosed inside parenthesis in a word document into numbered footnotes?
|
BobT | Word | 5 | 07-27-2018 01:17 PM |
| How to cross reference figures or tables when option is not given | timfoolery | Word | 4 | 06-12-2018 05:53 AM |
| Convert manual cross references in footnotes to other footnotes to automatic cross references | ghumdinger | Word VBA | 7 | 11-20-2014 11:47 PM |
| accept only new page numbers and cross references in review mode | guitargeorge | Word | 7 | 10-15-2013 03:32 PM |