Consulting

Results 1 to 3 of 3

Thread: Sequentially number superscripts

  1. #1
    VBAX Regular
    Joined
    May 2016
    Posts
    7
    Location

    Sequentially number superscripts

    Hello,

    is there a way to sequentially number superscripts in a document example

    the first superscript it finds it adds before the Range the number 1, the next superscript it finds it adds a 2 and so on and so forth.

    I have loads of superscripts but I would like them to be numbered so its easy to later reference.

    I have bits and peices

    Sub NumberSuperscripts(0
    
    
    Dim oRng As Range
    Dim oSuperscript as Range
    dim lngIndex as Long
    
    Set oRng = ActiveDocument.Range
    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Font.Superscript = True
    
        Do While .Execute(Forward:=True) = True
    
      For Each oSuperscript
          Set oRng = .Range
        
          oSuperscript.Insertbefore lngIndex
          lngIndex = lngIndex + 1
    
    End If
            oRng.Collapse wdCollapseEnd
        Loop
    End With
    thank you for any tips

    sam

  2. #2
    You are overthinking the problem. Try
    Dim oRng As Range
    Dim lngIndex As Long: lngIndex = 1
    
        Set oRng = ActiveDocument.Range
        With oRng.Find
            .Font.Superscript = True
            Do While .Execute(Forward:=True) = True
                oRng.InsertBefore lngIndex
                lngIndex = lngIndex + 1
                oRng.Collapse wdCollapseEnd
            Loop
        End With
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    May 2016
    Posts
    7
    Location
    Thank you Graham,

    that worked a treat!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •