Thread: [Solved] Macro Loop Help
View Single Post
 
Old 09-18-2015, 03:12 PM
Guessed's Avatar
Guessed Guessed is offline Windows 7 32bit Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Your sample file shows that each payslip has two lines that begin with the employee number and that some have leading spaces. The following macro seems to do the job on that file.
Code:
Sub Cleanup Payslips()
  With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^p^p^p^p"
    .Replacement.Text = "^p^p"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll 'tighten large spaces a bit
    
    .Text = "^13 [0-9]{7}  "
    .Replacement.Text = "^m^&"
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll 'add page breaks if leading spaced
    
    .Text = "^13[0-9]{7}  "
    .Replacement.Text = "^m^&"
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll 'add page breaks if not leading spaced
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote