View Single Post
 
Old 09-30-2023, 11:59 AM
Italophile Italophile is online now Windows 11 Office 2021
Expert
 
Join Date: Mar 2022
Posts: 542
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

It is really very simple. Just replace Selection with the range you want to find in. For example ActiveDocument.Content which is the same as the MainStory:

Code:
Sub ReplaceSuperscript()
    With ActiveDocument.Content.Find
        .ClearFormatting
        With .Font
            .Superscript = True
            .Subscript = False
        End With
        .Replacement.ClearFormatting
        With .Replacement.Font
            .Superscript = False
            .Subscript = False
        End With
        .Text = "[!^02]"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
        .Execute Replace:=wdReplaceAll
    End With
End Sub
If you need to replace throughout the entire document:

Code:
Sub ReplaceSuperscript()
    Dim story As Range
    For Each story In ActiveDocument.StoryRanges
        With story.Find
            .ClearFormatting
            With .Font
                .Superscript = True
                .Subscript = False
            End With
            .Replacement.ClearFormatting
            With .Replacement.Font
                .Superscript = False
                .Subscript = False
            End With
            .Text = "[!^02]"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
            .Execute Replace:=wdReplaceAll
        End With
    Next story
End Sub
Reply With Quote