PDA

View Full Version : [SOLVED:] Sequentially number superscripts



SamG
05-12-2016, 08:58 AM
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

gmayor
05-12-2016, 08:33 PM
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

SamG
05-13-2016, 05:58 AM
Thank you Graham,

that worked a treat!

:grinhalo: