Skip to content

Using COM with NVDA and Microsoft Word

Reef Turner edited this page Jul 26, 2016 · 5 revisions

This page provides a rough set of notes on getting started with COM calls via NVDA for Microsoft word.

Getting started

  • Open Microsoft word (with the content you wish to explore)
  • Press NVDA+ctrl+z to open the NVDA Python Console
  • Get access to a TextInfo object: tInfo = focus.makeTextInfo("caret")

Test the size of this range with:

   tInfo._rangeObj.start
   tInfo._rangeObj.end

You can modify these and then use tInfo._rangeObj.text to see what is in the range.

Exploring the interface

Using the Microsoft Word VBA Object model reference is helpful to explore what is available. See https://msdn.microsoft.com/EN-US/library/office/ff837519.aspx (if this link breaks, and you are having trouble finding this, try searching for "microsoft word range object" and going back up the documentation hierarchy). The Object model referred to in the VBA reference is available in your NVDA Python Console under tInfo._rangeObj. This allows you try getting the number of hyperlinks in the range, see the text for one, and its address:

tInfo._rangeObj.hyperlinks.count
tInfo._rangeObj.hyperlinks.item(1).range.text
tInfo._rangeObj.hyperlinks.item(1).address

Getting the method/property IDs

You will notice (in winword.cpp) that there are calls to _com_dispatch_raw_method and _com_dispatch_raw_propget which rely on defines set at the top of the file, such as #define wdDISPID_RANGE_START 3. Its important to be able to get these values. This can be done by querying the COM object for the ID for a name:

idisp = tInfo._rangeObj._comobj
idisp.GetIDsOfNames('hyperlinks')
# should output: [156]
Clone this wiki locally