Okay. Not getting help in the other newsgropu so I'm moving this here:
I started working on a program to read text out of some well organized word
docs. I've done this sort of thing in vba but not quite this extensively and
I'm not great with word automation. I know enough to be dangerous. LOL. I
need to open the doc (got that part done), locate certain phrases that are
in all of them and then read some text after those phrases into variables so
I can post them to a sql db. The part I'm struggling with is how to read the
doc. I'm not changing the docs in any way. They are deposited into a folder
on the network and I open and read them as they arrive. Setting up the
watcher for this in general is not a problem. I just need help reading the
docs in vb.net.
Here's some of what I have so far:
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Open("C:\SomeWordDoc.doc", , True)
Dim rng As Word.Range
With oWord.Selection
..HomeKey(wdStory)
rng = .Range
End With
rng.Find.Text = "Issue date::"
If rng.Find.Execute() Then
'MsgBox("found")
rng = oWord.Selection.Range
rng.End = rng.Next(wdLine, 1).End ' rng.MoveEnd(wdLine)
MsgBox(rng)
Else
MsgBox("Not found")
End If
'move to linebelow "Issue Date:" to get county
I decided that it might be best to read teh entire text into a string
variable and use RegEx to get the pieces I need. But there's a problem with
that. There are some places in the text where that will work adn I know how
to do that. But the bigger problem for me is how to read specific lines. For
example, I need to read the 4th line of each document. There is no specific
text in the 4th line that I can use RegEx to find it with so I have to read
the 4th line. I found this idea somewhere:
rng.Start = oDoc.Paragraphs(4).Range.Start
rng.End = oDoc.Paragraphs(4).Range.End
It seems to work but not sure if that's teh best way.
Then the last thing is that there is a large block of text in the middle of
these documents that I will need to read. I know the line it starts on but
have no idea which line it will stop on. But there is a line that follows it
that I can find using RegEx. Not sure how to grab that text based on those
ideas.
Help with the above will really get me started well on this. I'd really
apprecate it.
Thanks,
Keith