Subscript number with single letter but not in table

SmallFry
StarLounger
Posts: 91
Joined: 02 Sep 2018, 23:12

Subscript number with single letter but not in table

Post by SmallFry »

I've been using this f/r which works fine, but not there are areas within a table I do not want updated.

How can I skip tables?

Code: Select all

Sub FixSubscript2()
    With ActiveDocument.Range
        With .Find
            .Replacement.Font.Subscript = True
            .ClearFormatting
            .Replacement.ClearFormatting
            .Forward = True
            .Format = False
            .Wrap = wdFindStop
            .MatchWildcards = True
            .Text = "X[0-9]{1,}"
            .Replacement.Text = "^&"
            .Replacement.Font.Subscript = True
            .Execute Replace:=wdReplaceAll
            .Text = "X"
            .Replacement.Text = "^&"
            .Replacement.Font.Subscript = False
            .Execute Replace:=wdReplaceAll
        End With
    End With
End Sub

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Subscript number with single letter but not in table

Post by HansV »

Like this:

Code: Select all

Sub FixSubscript2()
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
        .ClearFormatting
        .Forward = True
        .Format = False
        .Wrap = wdFindStop
        .MatchWildcards = True
        .Text = "X[0-9]{1,}"
        Do While .Execute
            If Selection.Information(wdWithInTable) = False Then
                Selection.MoveStart
                Selection.Font.Subscript = True
            End If
            Selection.Collapse Direction:=wdCollapseEnd
        Loop
    End With
End Sub
Best wishes,
Hans

SmallFry
StarLounger
Posts: 91
Joined: 02 Sep 2018, 23:12

Re: Subscript number with single letter but not in table

Post by SmallFry »

This is perfect Hans. Thank you.