Consulting

Results 1 to 2 of 2

Thread: Not replacing kindly help where i missed

  1. #1
    VBAX Regular
    Joined
    Jun 2021
    Posts
    6
    Location

    Not replacing kindly help where i missed

    Sub Symbol()Options.DefaultHighlightColorIndex = wdBrightGreen
    Application.ScreenUpdating = False
    Dim rngStory As Range, i As Long
    Dim StrOld As String, StrNew As String
    StrOld = "ChrW(-3988)|ChrW(-4030)"
    StrNew = "ChrW(955)|ChrW(914)"
    For Each rngStory In ActiveDocument.StoryRanges
      With rngStory
        Select Case .StoryType
          Case wdMainTextStory, wdEndnotesStory, wdFootnotesStory
            With .Find
              .ClearFormatting
              .Replacement.ClearFormatting
              .MatchWildcards = True
              .Forward = True
              .Wrap = wdFindStop
              .Format = False
               For i = 0 To UBound(Split(StrOld, "|"))
                .Text = Split(StrOld, "|")(i)
                .Replacement.Text = Split(StrNew, "|")(i)
                .Replacement.Font.Name = "Times New Roman"
                .Replacement.Highlight = True
                .Execute Replace:=wdReplaceAll
               Next
            End With
        End Select
      End With
    Next rngStory
    Application.ScreenUpdating = True
    End Sub

  2. #2
    The following will work
    Sub Symbol()
        Options.DefaultHighlightColorIndex = wdBrightGreen
        Application.ScreenUpdating = False
        Dim rngStory As Range, i As Long
        Dim vOld As Variant, vNew As Variant
        vOld = Array(ChrW(-3988), ChrW(-4030))
        vNew = Array(ChrW(955), ChrW(914))
        For Each rngStory In ActiveDocument.StoryRanges
            With rngStory
                Select Case .StoryType
                    Case wdMainTextStory, wdEndnotesStory, wdFootnotesStory
                        With .Find
                            .ClearFormatting
                            .Replacement.ClearFormatting
                            .MatchWildcards = True
                            .Forward = True
                            .Wrap = wdFindStop
                            .Format = False
                            For i = 0 To UBound(vOld)
                                .Text = vOld(i)
                                .Replacement.Text = vNew(i)
                                .Replacement.Font.Name = "Times New Roman"
                                .Replacement.Highlight = True
                                .Execute Replace:=wdReplaceAll
                            Next
                        End With
                End Select
            End With
        Next rngStory
        Application.ScreenUpdating = True
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •