Text replacement Macro

I wrote a massive text replacement macro but it's very slow. my system info "Processor Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz, 2001 Mhz, 4 Core(s), 8 Logical Processor(s)". How can I optimize the VBA and make it replace the text faster.

  • Good afternoon 
    Could you share the VBA in a text document for assessment?
    A faster more up to date processor will always help too; but i am working on an i7-3770 @3.40GHz with 32GiB Ram and don't experience delays in my macro's.

    • Dim Tc(16)
      For x = 1 To 16

      'number input from the user
      Tc(x) = InputBox("Please ensure you enter the correct number" : " & x)

      Next x

      For i = 1 To 16

      Dim txtFindCTcHome As Variant
      txtFindCTcHome = "CTcH" & i & "#"
      Dim txtCTcHReplacer As Variant
      txtCTcHReplacer = aFh(Tc(i))
      Dim txtReplaceCTcHome As String
      txtReplaceCTcHome = UCase(txtCTcHReplacer)


      Dim txtFindCTcAway As Variant
      txtFindCTcAway = "CTcA" & i & "#"
      Dim txtReplacerCTcAway As Variant
      txtReplacerCTcAway = aFA(Tc(i))
      Dim txtReplaceCTcAway As String
      txtReplaceCTcAway = UCase(txtReplacerCTcAway)


      Dim txtFindTcHome As Variant
      txtFindTcHome = "TcH" & i & "#"
      Dim txtReplaceTcHome As Variant
      txtReplaceTcHome = aFh(Tc(i))


      Dim txtFindTcAway As Variant
      txtFindTcAway = "TcA" & i & "#"
      Dim txtReplaceTcAway As Variant
      txtReplaceTcAway = aFA(Tc(i))


      Dim txtFindNTc As Variant
      txtFindNTc = "Nt" & i & "#"
      Dim txtReplaceNTc As Variant
      If Tc(i) < 10 Then
      txtReplaceNTc = "0" & Tc(i)
      Else
      txtReplaceNTc = Tc(i)
      End If



      Dim d As Document
      Dim p As Page

      'the d as document makes the code run on all the pages the keyword appears

      For Each d In Documents
      For Each p In d.Pages

      '-------------Activator--------------------
      p.TextReplace txtFindCTcHome, txtReplaceCTcHome, True, False
      p.TextReplace txtFindCTcAway, txtReplaceCTcAway, True, False
      p.TextReplace txtFindTcHome, txtReplaceTcHome, True, False
      p.TextReplace txtFindTcAway, txtReplaceTcAway, True, False
      p.TextReplace txtFindNTc, txtReplaceNTc, True, False

      Next p
      Next d

      Next i
      Thanks
  • Are you using the optimization code in your macro?

    Sub YadaYada()
    Optimization = True
    __________________

    your code to make things happen

    __________________

    Optimization = False
    ActiveWindow.Refresh
    End Sub

  • Even with Optimization = True (as suggested by Myron), some text operations in CorelDRAW can be very slow.

    That includes both (1) large numbers of text shapes and (2) individual text shapes that have a large number of characters.

    I write that from personal experience; I don't know how those affect the specific types of text operations that you are trying to perform.