Sub Copy()
'
' Copy Macro
' Macro recorded 08/10/2009 by XXXXXXXXXXX'
Dim searchstrings(10) As String
Dim position1 As Integer
Dim position2 As Integer
''Dim position3 As Integer
Dim enddoc As Boolean
searchstrings(1) = "Payment"
searchstrings(2) = "Beneficiary Details Number"
searchstrings(3) = "Country"
searchstrings(4) = "Name"
searchstrings(5) = "Payment Instructions"
searchstrings(6) = "Payment Details"
searchstrings(7) = "Account Number"
searchstrings(8) = "Bank"
searchstrings(9) = "Bank"
searchstrings(10) = "Payment"
Selection.Move wdCharacter, -Selection.Start
Dim offset As Integer
enddoc = False
While Not enddoc
i = 1
offset = 0
finishstring = " "
While i < 10
Selection.Find.ClearFormatting
With Selection.Find
.Text = searchstrings(i)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
position1 = Selection.End + 1
If i = 8 Then
Selection.MoveStart wdCharacter, 5
Selection.MoveEnd wdCharacter, 9
If UCase(Trim(Selection.Text)) <> "SWIFT ID" Then
finishstring = finishstring & ","
offset = 1
Selection.MoveStart wdCharacter, Len(Selection.Text)
position1 = position1
With Selection.Find
.Text = searchstrings(i + 2)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
enddoc = Selection.Start = 0
position2 = Selection.End
Selection.MoveEnd wdCharacter, -Len(searchstrings(i + 2))
Selection.MoveStart wdCharacter, -(position2 - position1 - Len(searchstrings(i + 2)))
j = 1
While j <= Len(Selection.Text)
If Mid(Selection.Text, j, 1) = vbCrLf Then
Selection.MoveStart wdCharacter, 1
End If
j = j + 1
Wend
finishstring = finishstring & Replace(Trim(Selection.Text), vbCrLf, " ")
Else
Selection.MoveStart wdCharacter, Len(Selection.Text)
position1 = position1 + 9
With Selection.Find
.Text = searchstrings(i + 1)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
enddoc = Selection.Start = 0
position2 = Selection.End
Selection.MoveEnd wdCharacter, -Len(searchstrings(i + 1))
Selection.MoveStart wdCharacter, -(position2 - position1 - Len(searchstrings(i + 1)))
j = 1
While j <= Len(Selection.Text)
If Mid(Selection.Text, j, 1) = vbCrLf Then
Selection.MoveStart wdCharacter, 1
End If
j = j + 1
Wend
finishstring = finishstring & Replace(Trim(Selection.Text), vbCrLf, " ")
End If
Else
Selection.MoveStart wdCharacter, Len(Selection.Text)
With Selection.Find
.Text = searchstrings(i + 1)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
enddoc = Selection.Start = 0
position2 = Selection.End
Selection.MoveEnd wdCharacter, -Len(searchstrings(i + 1))
Selection.MoveStart wdCharacter, -(position2 - position1 - Len(searchstrings(i + 1)))
j = 1
While j <= Len(Selection.Text)
If Mid(Selection.Text, j, 1) = vbCrLf Then
Selection.MoveStart wdCharacter, 1
End If
j = j + 1
Wend
If i = 1 Then
finishstring = finishstring & Replace(Replace(Trim(Selection.Text), "Accepted", ""), vbCrLf, " ")
Else
finishstring = finishstring & Replace(Trim(Selection.Text), vbCrLf, " ")
End If
End If
If i + offset < 9 Then finishstring = finishstring & ","
i = i + 1 + offset
Wend
MsgBox (Replace(Replace(finishstring, vbCr, " "), vbLf, " "))
Wend
End Sub