The following should work for a given folder selected from the macro
Sub ExtractAddresses()
Dim SourceDoc As Document
Dim TargetDoc As Document
Dim oRng As Range
Dim strFile As String
Dim strPath As String
Dim iFld As Integer
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder containing the documents and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
Application.ScreenUpdating = False
strFile = Dir$(strPath & "*.do?")
Set TargetDoc = Documents.Add
While strFile <> ""
Set SourceDoc = Documents.Open(strPath & strFile)
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "[A-Z]{2} [0-9]{5}"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
While .Execute = True
Set oRng = Selection.Range
oRng.MoveStart wdParagraph, -3
TargetDoc.Range.InsertAfter oRng & vbCr & vbCr
Wend
End With
End With
SourceDoc.Close SaveChanges:=wdDoNotSaveChanges
strFile = Dir$()
Wend
Application.ScreenUpdating = True
TargetDoc.Activate
End Sub
Either there would be a blank line which can be tracked by vbCr or
there will be word CC1, CC2, CC3 .....
for example
Martha Stewart
72 Mount Auburn Street
Marlborough, MA 02472
Some text lines will be here
Some text lines will be here
Some text lines will be here
Some text lines will be here
Some text lines will be here
CC1
Gregory Shlimovich
73 West Main Street
Waltham, MA 01748
CC2:
Savita Sharma
74 Main Street
Framingham, MA 02053
Like in the example above there are three addresses