Skip to main content

This article explains how to use the MS Word printout automation object from COBOL.

Problem:

The printout automation method in Microsoft Word allows you to print out specific page ranges from your application. However there are a lot of different options available for this method and most are not relevant for page ranges. How can you call this from COBOL ?

Resolution:

You can use OLE Named Parameters with the printout method to print a page range. An example of this is:


mftech***** Use OLE Named parameters
mftech invoke olesup "setNamedParameters" using by value 4 size 4
mftech set wdPrintFromTo of ws-range to true
mftech invoke theDocument "PrintOut"
mftech using by reference z"Background"
mftech by value -1
mftech by reference z"Range"
mftech by value ws-range
mftech by reference z"From"
mftech by reference "1"
mftech by reference z"To"
mftech by reference "2"

Before you use the “PrintOut” method you need to use the “setNamedParameters” call. This specifies that the next OLE Automation call will specify named parameters. This allows you to supply the name of the parameter and then actual parameter value. The parameter names need to be null terminated which is specified by preceding the string with z (z”Range”).

Incident Number: 2282931

Old KB# 14491