![]() |
|
#1
|
||||
|
||||
![]()
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] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
mdhg | Word VBA | 20 | 03-06-2024 08:07 AM |
Selecting and moving text boxes identified by specific text. | Chayes | Word VBA | 8 | 02-22-2016 07:01 AM |
![]() |
Chayes | Word VBA | 6 | 06-24-2012 06:54 PM |
Selecting styled text | Caroline | Word | 5 | 02-15-2011 12:55 PM |
Selecting a Text Box | gajesh | Word | 0 | 09-02-2009 11:45 PM |