View Single Post
 
Old 01-17-2014, 07:57 AM
nsyrax nsyrax is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jan 2014
Posts: 1
nsyrax is on a distinguished road
Default Help with VBA script

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:

Code:
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
Reply With Quote