Reading From Word Document

How can I open and read a Microsoft Word Document?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

lbkConnect With a Mentor Commented:
You can either use OLE (Reference Office, word object library):

etc etc

or you can use VBA, but then you would have to initiate execution in word (There is ways around it, but complicated)

More info = more points

use automation.  Put a reference in to Work Type Library.  Then you can do declare a variable of Word.Application.  Then there is all sorts of properties that you can look through to do whatever you want with the document.  You can use YourVariable.Range.FormattedText and this will return all of the text in the document.  Before you do this you will have to do YourVariable.Open blahfilename

In your class :

Private wd As Word.Application     ' Handle on Word application

' Create a Word instance
If wd Is Nothing Then
    Set wd = CreateObject("word.application")
    If Not wd Is Nothing Then
        wd.Visible = False ' or True
        wd.DisplayAlerts = wdAlertsNone ' or 1
        '- Word error ?
    End If
End If

and to close it :

If Not wd Is Nothing Then
   Call wd.Quit(wdDoNotSaveChanges)
   Set wd = Nothing
End If

In the Project -> References, add a ref. to Microssoft Word 8.0 Object Library, so you can access to the constants, aso and define the wd var of Word.Application type (Early binding) instead of the more generic & less efficient Object type (Late binding)

Hope it helps

CU around

mh149Author Commented:
lbk - that amount of info is not worth much more than a comment...
would have given it to ESI has he proposed the answer
All Courses

From novice to tech pro — start learning today.