Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-21-2021, 12:15 AM
laith93 laith93 is offline Placing numbers of cross-references of tables and figures inside parenthesis Windows 10 Placing numbers of cross-references of tables and figures inside parenthesis Office 2019
Competent Performer
Placing numbers of cross-references of tables and figures inside parenthesis
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default


Mr. Andrew, I edited your code to work for the entire document according to your code
Thank so much again

Code:
Sub RestrictXRefsForEntireDoc()

'Putting cross references number inside parenthesis and convert Figure and Table to lowercase
'Developed by Mr. Andrew - msofficeforums.com

  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
  For Each aFld In ActiveDocument.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
End Sub
Reply With Quote
Reply

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
Placing numbers of cross-references of tables and figures inside parenthesis 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:11 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft