Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting Text from Word 2000 into Excel 2000

Status
Not open for further replies.

jdrury

Programmer
Nov 25, 2002
2
US
Heelo,

I have been trying to extract requirements form a word document and pull them into Excel for traceability.

The information on VBA and MS applications seems *very* slim, so please be gentle :)

All items are denoted by the Text Shall([section#]) in the Word doc, when I toggle field codes they in the form of "shall ({ REF _Ref2445166 \r \h}b)". I need to recursively iterate through the document pulling out the sentences that contain these requirements and putting them into an excel worksheet.

I am to the point where I can open the document and find the "shall" text, but when I try to use
" myWord.Selection.MoveRight Unit:=wdCharacter, Count:=1"

I get:
"Run-time error '4120', Application-defined or object-defined error"

It is my understanding that this should select the rest of the sentence text.


How do I do this? If possible please post code as well as descriptions.

Thanks
-Jonathan
 
I suspect the error is because the next character is a field code, not a normal character. However, I think you're actually looking to move to the end of the sentence, not to the next character, so you need to use wdSentence instead of wdCharacter, and to SELECT the text you'll also have to set the Extend parameter:

myWord.Selection.MoveRight Unit:=wdSentence, Count:=1 Extend:=wdExtend

Let us know if that helps.
Rob
[flowerface]
 
I tried what you suggested, but I got the same error. 4120...

I also need help on the rest of what I am trying to do. thanks!

-Jon

Here is the code:

Public Function FindShall()

Dim myWord As Object
Set myWord = CreateObject("Word.Application")

myWord.ChangeFileOpenDirectory "C:\WINDOWS\Desktop\"
myWord.Documents.Open Filename:="test.doc" ', ReadOnly:=True

myWord.Visible = True
myWord.Activate

myWord.Selection.Find.Text = "Shall"
myWord.Selection.Find.Execute

myWord.Selection.MoveRight Unit:=wdSentence, Count:=1, Extend:=wdExtend

End Function
 
I don't know why you're getting the error. You could try to put ...selection.collapse before the .moveright method. If that fails, I'd record a macro doing the same thing using the macro recorder and see what code Word generates.
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top