Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Automation - Finding strings
Message
From
10/08/2001 12:30:20
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00541649
Message ID:
00542359
Views:
19
>Hi, I need to scan all Word documents from a hard disk, trying to find some kind of documents. I know that these documents have 2 strings, one above the other, like:
>
>First string in line 14
>Second string in line 15
>
>These strings can be found in another sections of the document, but in just one case (the one that I need, one above the other) they identify the documents that I´m looking for.
>I know how to search the strings, but I don´t know how to retrieve the lines where they were found. Any ideas?
>
>Regards,

Jose,
To get lines from word pagination needs to be enabled and current view shouldn't be draft. Provided these precautions you can use Information() as Yuri suggested. ie :
#INCLUDE 'wdconst.h'
lcDir = getdir()
lnDocs = adir(arrDocs,lcDir+'*.doc')
lcSearch1 = 'First String to find'
lcSearch2 = 'Next String to find'
oWord=CREATEobject("Word.Application")
With oWord
  .Options.Pagination = .t.
  For ix = 1 to lnDocs
    .Documents.Open(lcDir+arrDocs[ix,1])
    .ActiveDocument.ActiveWindow.View.Draft = .f.
    With .ActiveDocument.Content.Find
      .ClearFormatting
      If .Execute(lcSearch1+'^w^p'+lcSearch2,.f.) ;
          or .Execute(lcSearch1+'^p'+lcSearch2,.f.)
        ? 'Found in document '+lcDir+arrDocs[ix,1]+;
          ' at line '+transform(.Parent.Information(wdFirstCharacterLineNumber))
      Endif
    Endwith
    .ActiveDocument.Close(wdDoNotSaveChanges)
  Endfor
  .Quit
Endwith
This is not a bulletproof search and line number might change with just layout change. In your case getting the whole content to a string and making search in it might be more correct approach.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform