How to scan/parse through Word Document?

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

What I want to do is write a program that reads through a
Word Document, finds certain words or sentences I want,
and then paste into an Excel spreadsheet.

I dont know much about C#. But I learned how to use
those COM Interop things. And Im able to write code that
allows me to open existing Word documents and existing
Excel spreadsheets. And I know how to write into
specific columns and rows of the spreadsheet.

But I dont know what functions to use or the code for my
parser to look through the Word Document. Ive found
through the Object Browser some Objects in the
microsoft.office.interop.word assembly that may help.
Some of the members in the Range() object and Selection()
object seem like they may be what Im looking for. But Im
not sure if they are or even how to use them.

Any help would be much appreciated. Thanks.
 
..Find method is probably what you want to use. Here's a good way to start.
Open up a word document and start recording a macro. Then, do whatever you
think you want your program to do. End the macro. Look at the code. It
will have a lot of extra crap in it, but it will give you a good insight
into how Word works..

You can also load the contents into a stream and use Regular Expressions to
parse it....

HTH,

Bill
 
You can match patterns with WildCards...look in the Find Dialog under More
or Advanced depending on the version you are using. You can use % and a few
other ones...

You can set string s = .Find--whatever
 
You've been a lot of help so far... thanks.

one more question which may be kind of dumb. But in my
code i wrote...

_Document document = application.Documents.Open(...etc...)

And from there I can use document.Range(), document.SaveAs
(), document.Words.First.InsertBefore().... etc...

but i cant use the functions under Selection such as
Find.Execute(), MoveUp() ..etc...

so do I have write something like...

Selection select = ?

set that equal to something and then from there use
select.MoveUp() ?

if so what would i set Selection select equal too?

thanks
 
Back
Top