This is the code that Co-Pilot wrote for me, that doesn't work. It has elements of Paul's replace that, as a novice, I can follow. As I sat, I am trying to get my head around VBA and I hope that making this work will give me some good tuition.
Sub DeleteSuperscriptText()
Dim rng As Range
Dim startPos As Long
Dim endPos As Long
Set rng = ActiveDocument.Content
With rng.Find
.ClearFormatting
.Font.Superscript = True
.Text = "\(*\)"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchWildcards = True
Do While .Execute
If rng.Font.Superscript = True Then
startPos = rng.Start
endPos = rng.End
' Adjust the range to select the characters between "(" and ")"
rng.SetRange startPos + 1, endPos - 1
' Delete the characters
rng.Delete
' Move the cursor to the next non-superscript position
Set rng = ActiveDocument.Range(rng.End, ActiveDocument.Content.End)
If rng.Find.Execute(FindText:="", Forward:=True, Wrap:=wdFindStop) Then
If rng.Font.Superscript = False Then
rng.Collapse wdCollapseStart
Exit Sub
End If
End If
End If
Loop
End With
End Sub
|