![]() |
|
#1
|
|||
|
|||
![]()
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 |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
LLLCa947 | Word VBA | 6 | 11-21-2024 01:44 AM |
![]() |
ra_beale | Word VBA | 4 | 09-05-2022 07:09 AM |
![]() |
Swarup | Word | 2 | 07-09-2022 07:42 PM |
![]() |
TheBigBoss | Word VBA | 5 | 06-10-2022 06:14 AM |
![]() |
Swarup | Word | 4 | 07-18-2019 05:51 PM |