Extraction from MS Word files to Excel?

R

Rich

I want to go through a huge folder of files (5,000+) and when I find a
particular word (case sensitive), I want to skip a line, and then copy
whatever follows on that line into Excel. How would I do this? Thank you so
much in advance for any help!
 
D

Doug Robbins - Word MVP

Are you talking about lines or paragraphs. What terminates each line? Is it
a ¶? Also what exactly do you mean by "SKIP a line, and then copy whatever
follows on THAT line...? Give an example about how what you want to copy
relates position-wise to the word.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Rich

Hi Doug:
Thanks for your assitance. I want to go through each document, find a
specific word, then retrieve the information that follows two lines below
that word. A ¶ ends each line in the Word doc.

For example, I want to go through each document, find the word EXPERIENCE,
skip a line underneath that word, and copy the information that follows until
I hit ¶.

Here is an example of the information I am looking to retrieve and fill up
an Excel spreadsheet:

EXPERIENCE¶
¶
COMPANY NAME, City, State¶

I want to copy COMPANY NAME and City/State (if provided, it is not always
included) into an Excel sheet.

I hope this makes it clearer.
 
D

Doug Robbins - Word MVP

The following (which I haven't actually tested) should create a new document
into which it will insert the COMPANY NAME, City, State from each occurrence
of EXPERIENCE in each of the files in the folder.

You can then just copy and paste all of that information from that document
into Excel.

Dim MyPath As String
Dim MyName As String
Dim Source As Document
Dim Target As Document
Dim myrange As Range

Set Target = ActiveDocument
'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() <> -1 Then Exit Sub
MyPath = .Directory
End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If

'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
Set Source = Documents.Open(MyName)
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="EXPERIENCE", Forward:=True,
Wrap:=wdFindStop) = True
Set myrange = Selection.Range
With myrange
.MoveEnd Unit:=wdParagraph, Count:=3
.MoveStart Unit:=wdParagraph, Count:=2
End With
Target.Range.InsertAfter myrange
Loop
End With
Source.Close wdDoNotSaveChanges
MyName = Dir
Loop

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top