Skip to content

Read Word Document Using NetOffice 1.60

I needed to look through a Word document for an application running the .NET 2.0 framework. Here is how I did it using NetOffice 1.60 which can be downloaded via NuGet in Visual Studio.

Imports Word = NetOffice.WordApi
Imports NetOffice.WordApi.Enums

Module Module1

    Sub Main()
    End Sub

    Private Sub readWordDoc()

        ' start word and turn off msg boxes
        Dim wordApplication As New Word.Application
        wordApplication.DisplayAlerts = WdAlertLevel.wdAlertsNone

        ' open document as read only
        Dim myDocument As Word.Document
        myDocument = wordApplication.Documents.Open(System.IO.Path.GetFullPath("MyDoc.docx"), False, True)

        ' get document's content
        Dim content As String
        content = myDocument.Content.Text

        ' close doc

        ' output content 

    End Sub

End Module
Published inVBA

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *