Consulting

Results 1 to 11 of 11

Thread: Speeding up a replace macro running through a long text

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,442
    Location
    From your description, it seems to me all you need is:
    Sub Duplicate_And_Replace()
    Application.ScreenUpdating = False
    Const sTEXT = "k=""ABCD"""
    Const sREPLACETEXT = "k=""EFGH"""
    With ActiveDocument.Range.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = "([!^13]@)" & sTEXT & "([!^13]@^13)"
      .Replacement.Text = "\1" & sREPLACETEXT & "\2\1" & sTEXT & "\2"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchWildcards = True
      .Execute Replace:=wdReplaceAll
    End With
    Application.ScreenUpdating = True
    End Sub
    Last edited by macropod; 01-15-2023 at 05:50 PM.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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