Consulting

Results 1 to 2 of 2

Thread: Find/Replace through file

  1. #1

    Lightbulb Find/Replace through file

    Hi all,

    i'm trying to find a way to make several find/replace through file with a specific criteria as following:

    this text:

    m:para-id="0"

    is repeated more than 200 times at the file, i want to find them and go through file then replace to

    m:para-id="1-tu1"
    m:para-id="1-tu1"
    m:para-id="1-tu2"
    m:para-id="1-tu2"

    m:para-id="1-tu3"
    m:para-id="1-tu3"
    m:para-id="1-tu4"
    m:para-id="1-tu4"


    .......etc

    in other words i need to find the first two instances and change the "0" to
    "1-tu1"
    then the second two instances and change the
    the "0" to "1-tu2" .....etc


    1.jpg

    i have attache sample file for before and after


    Thanks in advance
    Attached Files Attached Files

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    759
    Location
    Option Explicit
    
    
    Sub test()
      Dim r As Range
      Dim n As Long
      
        Set r = ActiveDocument.Range
        
        With r.Find
            .Text = "(m:para-id=)""0"""
            .MatchWildcards = True
            Do
                .Replacement.Text = "\1""1-tu" & Int(n / 2 + 1) & """"
                .Execute Replace:=wdReplaceOne
                r.Collapse wdCollapseEnd
                If .Found = False Then Exit Do
                n = n + 1
            Loop
      End With
      
    End Sub

    マナ

Tags for this Thread

Posting Permissions

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