View Single Post
 
Old 06-28-2018, 07:08 AM
XRope XRope is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Jun 2018
Posts: 17
XRope is on a distinguished road
Default Extract List of terms and combine on a Table

Hi everyone,

I would like to make a macros to extract text within parentheses and all countries names in order of apearence within 2 open word documents and combine them on a new document for revision.
I suppose I have to provide the list of countries

I have a macro to extract and put on a table text within parentheses but it only works for one document. I want to add extraction of all countries listed in the doc too. and that it processes both open documents. There is no need for autosave since its only for revision.

Here the macro for extracting text within parentheses.

Sub ExtractText()
Dim cDoc As Word.Document, nDoc As Word.Document
Dim cRng As Word.Range, nRng As Word.Range

Set cDoc = ActiveDocument
Set nDoc = Documents.Add

Set cRng = cDoc.Content
Set nRng = nDoc.Content

cRng.Find.ClearFormatting
With cRng.Find
.Forward = True
.Text = "("
.Wrap = wdFindStop
.Execute
Do While .Found
cRng.Collapse Word.WdCollapseDirection.wdCollapseEnd
cRng.MoveEndUntil Cset:=")", Count:=Word.wdForward
nRng.FormattedText = cRng.FormattedText
nRng.InsertParagraphAfter
nRng.Collapse Word.WdCollapseDirection.wdCollapseEnd
cRng.Collapse Word.WdCollapseDirection.wdCollapseEnd
.Execute
Loop
End With
End Sub


thanks a lot
Reply With Quote