Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-26-2023, 12:12 AM
Shelley Lou Shelley Lou is offline VBA Highlight additional cross references Windows 10 VBA Highlight additional cross references Office 2016
Competent Performer
VBA Highlight additional cross references
 
Join Date: Dec 2020
Posts: 170
Shelley Lou is on a distinguished road
Default VBA Highlight additional cross references

I have been working with some code to highlight the number after any clause, paragraph, part or schedule references but this only highlights the number immediately following the word (see ref1).



Ref 1.JPG

Code:
StrFndA = "[Aa]rticle,[Aa]ppendix,[Cc]lause,[Pp]aragraph,[Pp]art,[Ss]chedule" 'highlight numbers after these words
For Each Rng In ActiveDocument.StoryRanges
  With Rng
    Select Case .StoryType
      Case wdMainTextStory, wdFootnotesStory
      For i = 0 To UBound(Split(StrFndA, ","))
          With .Duplicate
            With .Find
              .ClearFormatting
              .Replacement.ClearFormatting
              .Forward = True
              .Wrap = wdFindStop
              .MatchWildcards = True
              .text = Split(StrFndA, ",")(i) & "[s ^s]@[0-9.]{1,}"
            End With
            Do While .Find.Execute
              .MoveStart wdWord, 1
              .HighlightColorIndex = wdTurquoise
              .Collapse wdCollapseEnd
            Loop
          End With
        Next
I am trying to expand the code to include any additional cross reference numbers that may follow a comma or the words 'or', 'and', 'and/or'.

At the moment I'm using the following code to try to capture the rest of the manual cross reference numbers which as you can see is not highlighting all the references and I wondered if there was a more efficient way of highlighting the additional references numbers.

Ref 2.JPG

Code:
.text = "([0-9]@{1,}.[0-9]{1,})"                 'Highlight manual cross refs separated by period
          .Replacement.text = ""
          .Execute Replace:=wdReplaceAll
          .text = "([0-9]@{1,}.[0-9]{1,}.[0-9]{1,})"
          .Replacement.text = ""
          .Execute Replace:=wdReplaceAll
          .text = "([0-9]@{1,}.[0-9]{1,}.[0-9]{1,}.[0-9]{1,})"
          .Replacement.text = ""
          .Execute Replace:=wdReplaceAll
Would appreciate any advice given.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
cross-references gurpreetsandhu Word 1 06-06-2019 04:13 PM
About Cross-references mohsen.amiri Word 1 01-19-2017 10:35 AM
Convert manual cross references in footnotes to other footnotes to automatic cross references ghumdinger Word VBA 7 11-20-2014 11:47 PM
VBA Highlight additional cross references Cross-References acolussi Word 9 05-16-2013 02:11 AM
Cross References egcharles Office 0 04-19-2009 06:20 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:20 AM.


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