Advertisement
osipyonok

IncrementalReplacementMacro

Jan 26th, 2022
1,792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub IncrementalReplacementMacro()
  2.     Dim UndoObject As UndoRecord
  3.     Set UndoObject = Application.UndoRecord
  4.     UndoObject.StartCustomRecord ("Incremental replacement macro")
  5.     Application.ScreenUpdating = False
  6.     With ActiveDocument.Range
  7.       With .Find
  8.         .ClearFormatting
  9.         .Text = "10500" 'All enteries of this text will be replaced
  10.        .Replacement.Text = ""
  11.         .Forward = True
  12.         .Wrap = wdFindStop
  13.         .Execute
  14.       End With
  15.       Counter = 777 'The first value of the id to be used
  16.      Do While .Find.Found
  17.         .Text = "¹" + LTrim(Str(Counter)) 'Expression that calculates text for replacement
  18.        Counter = Counter + 1 'Update the value of counter for the next replacement
  19.        .Collapse wdCollapseEnd
  20.         .Find.Execute
  21.       Loop
  22.     End With
  23.     Application.ScreenUpdating = True
  24.     UndoObject.EndCustomRecord
  25. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement