View Single Post
 
Old 04-06-2016, 04:33 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try adding the following macro to the document you want the output to go to. It includes a folder browser, so all you need do is select the folder to process and a table containing the 'to' & 'cc' data will be created at the end of your document.
Code:
Sub HarvestDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
Dim StrTxt As String, Rng As Range
Set Rng = ActiveDocument.Range.Characters.Last
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With ActiveDocument 'wdDoc
      With .Range
        With .Find
          .ClearFormatting
          .Text = "Memorandum to^l*From^l"
          .Replacement.Text = ""
          .Forward = True
          .Wrap = wdFindContinue
          .Format = False
          .MatchWildcards = True
          .Execute
        End With
        If .Find.Found = True Then
          StrTxt = .Text
          Do While InStr(StrTxt, vbCr & vbCr) > 0
            StrTxt = Replace(StrTxt, vbCr & vbCr, vbCr)
          Loop
          StrTxt = Replace(Replace(.Text, "Memorandum to" & Chr(11), ""), vbCr & "From" & Chr(11), "")
          StrTxt = Replace(Replace(StrTxt, vbCr, vbTab), "cc" & Chr(11), "")
          Do While Right(StrTxt, 1) = vbTab
            StrTxt = Left(StrTxt, Len(StrTxt) - 1)
          Loop
          Rng.InsertAfter StrTxt & vbCr
        End If
      End With
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Rng.ConvertToTable vbTab
Set wdDoc = Nothing: Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote