View Single Post
 
Old 11-01-2021, 04:26 PM
davidjm davidjm is offline Windows 10 Office 2016
Novice
 
Join Date: Jun 2018
Posts: 18
davidjm is on a distinguished road
Default

Hi Andrew,
I've had a think about this and have decided to only add 2 to all page numbers and keep the format of the rollover numbers as they are (number of digits is unchanged).

I wasn't asked to fix the index and as you say Word has built-in functionality for indexing.

So using your code I have the start of 2 routines I need to run, 1st updates all page numbers that are not rollover trailing page numbers
Code:
Sub FindPattern()
  Dim aRng As Range, str As String, int1 As Integer, int2 As Integer, arrStr() As String, msg As String, x As String
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .ClearFormatting
    .MatchWildcards = True
      .Text = " [0-9]{2,3}"
    Do While .Execute = True
      arrStr = Split(aRng.Text, " ")
      For i = LBound(arrStr) To UBound(arrStr)
         If IsNumeric((arrStr(i))) Then
               int1 = CInt(arrStr(i)) + 2
        End If
      Next i
' Need help here to update the index fields
'       int1 = CInt(arrStr(0)) + 2
'       int2 = CInt(arrStr(1)) + 2
'       aRng.Text = int1 & "-" & int2
'      aRng.Collapse Direction:=wdCollapseEnd
'      aRng.End = ActiveDocument.Range.End
    Loop
  End With
End Sub
Then I need to run a second routine to update all the rollover trailing page numbers and keep the same number of digits as the original

Code:
Sub FindToPage()
  Dim aRng As Range, str As String, int1 As Integer, int2 As Integer, arrStr() As String, msg As String, x As String
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .ClearFormatting
    .MatchWildcards = True
    .Text = "–[0-9]{1,3}"
    Do While .Execute = True
      arrStr = Split(aRng.Text, "–")
      For i = LBound(arrStr) To UBound(arrStr)
       If IsNumeric(arrStr(i)) Then
          If CInt(arrStr(i)) > 7 And CInt(arrStr(i)) < 10 Then
             int1 = CInt(arrStr(i)) - 8
           Else
             int1 = CInt(arrStr(i)) + 2
          End If
       End If
      Next i
     Loop
  End With
End Sub
If you could just complete the above routines to update the original file, it would be very much appreciated

This index was created manually so just updating the page numbers is enough.
Thanks for your time and all your input, I've learned a great deal
Reply With Quote