PDA

View Full Version : VBA to pull data from word document



jdooley3
11-07-2013, 09:17 AM
I need help in creating code to pull data from a word document into an excel chart.

Background: I have a list with hundreds of names. I need to scan a word document for those names and on every match I need to pull the name from word into an excel worksheet I have. My current strategy was to create a word macro to find the names and highlight them and then use a code to extract all hihglighted text. Does this seem reasonable?

I have been told it may be easier to write a code in excel that opens the word document, scans it and then closes it. Below is the code I have written (extremely basic!) to highlight a given word. Here is what I need help with:

1. I need more than one word highligted, there a few hundred, all of which are based in a document
2. Use document with list to replace "olympics" so that all of those words will be pulled
3. Extract matches from the word document into an excel sheet

I am looking for any and all help, I am new to vba but I learn very fast and am able to catch on quickly.

Dim sFindText As String
sFindText = "Olympics"
Selection.ClearFormatting
Selection.HomeKey wdStory, wdMove
Selection.Find.ClearFormatting
Selection.Find.Execute sFindText

Do Until Selection.Find.Found = False
Selection.Range.HighlightColorIndex = wdYellow

Selection.MoveRight

Selection.Find.Execute
Loop