Read Text from a Microsoft Word Document in LabVIEW

Updated Jan 12, 2023

Reported In

Software

  • LabVIEW Full
  • LabVIEW Base

Issue Details

I would like to read plain text from a Microsoft Word document in LabVIEW. Is this possible?

Solution

You can read text from a Microsoft Word document using the Microsoft ActiveX API. See Figure 3. for an overall reference. The basic process is as follows:
 
  1. Open a reference to the Microsoft Word application using the LabVIEW Automation Open function.
  2. Access the Documents object, a property of the newly created Application object.

Figure 1: Opening the Applications and Documents objects
  1. Invoke the Open method, and specify the path to the document you wish to open.
  2. Access the Content property of the Document object. This is a Range object comprising the entirety of the opened document.
  3. Access the Text property of the Content object. This returns a string containing the text of the Word document.

Figure 2: Reading the text from the document
For more information on using ActiveX in LabVIEW, see White Paper: ActiveX and LabVIEW . For more information on available properties and methods of Microsoft Word, see the MSDN reference.

Figure 3: The full code for reading from the Word document

Additional Information

Please be aware that you must have Microsoft Office installed on your system for this to be possible.