0

I have a .txt file that needs to be cleaned up. It needs to have a page break before the word "Individual" on every page. It also needs to be Courier New 8.5pts, top and bottom margin of 0.5in, left and right margin of 1in. I modified another script I found (shown below) and it almost gets me there. the problem is there is some unneeded text before "Individual", which is the number 1 followed by several spaces and 3 carraige returns. I need to delete this text. Below is the script as it is currently:

Sub InsertPageBeforeDate()
  Dim lngPos As Long
  Application.ScreenUpdating = False
  Selection.HomeKey Unit:=wdStory
  Selection.WholeStory
    Selection.Font.Name = "Courier New"
    Selection.Font.Size = 8.5
  With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "Individual"
    .Format = False
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    Do While .Execute
        If Selection.Information(wdFirstCharacterLineNumber) > 1 Then
            lngPos = Selection.Start
            Selection.MoveLeft Unit:=wdWord, Count:=2, Extend:=True
            If LCase(Selection.Text) <> "of " Then
                Selection.Collapse Direction:=wdCollapseEnd
                Selection.InsertBreak Type:=wdPageBreak
            End If
            ActiveDocument.Range(Start:=lngPos + 4, End:=lngPos + 4).Select
        End If
    Loop
End With
Application.ScreenUpdating = True
End Sub
Mr.Syrax
  • 396
  • 1
  • 9
  • 26
  • What "Find" and "Replace" strings have you tried to find the stuff you do not want? –  Jan 17 '14 at 14:59
  • I'm a bit of a n00b, so I honestly am not 100% sure how to. – Mr.Syrax Jan 17 '14 at 15:07
  • Here, you are encouraged to look for yourself before asking other people to use their time on your behalf. For example, you could do a search for "Microsoft Word find replace special characters" –  Jan 17 '14 at 15:59
  • I know how to do a find/replace from within Word, and I tried making a macro, then going into VB to copy/paste the resulting code into my script, but it seemed no matter where I put it, I got an error – Mr.Syrax Jan 17 '14 at 16:08

0 Answers0