Error calling Word OLE

Symptom

An error occurs when executing the following code using Word OLE in PowerBuilder:

lole_object.ActiveWindow.Selection.InsertAfter(‘abc’)

Environment

PowerBuilder 2017 or later

MS Word 2007 or 2013

Cause

Starting from MS Word 2016, it supports the Read Mode. After you open a document, it is in Read Mode by default. So it fails to execute the insert operation.

Solution

After you open the document in OLE, execute the following code to turn off Read Mode:

lole_object.ActiveWindow.View.ReadingLayout = False