Skip to main content

Problem:

OLE demo that calls Microsoft Word and does a find/replace

Resolution:

INTRODUCTION

==========

This demo shows how to write an OLE Automation client to Word 97 in a series of simple stages.

DESCRIPTION

=========

This demo shows:

o     How to start and stop Word 97 from COBOL

o     How to load a document into Word 97, edit and print it.

o     How to deal with exceptions and events generated by Word 97.

There are five versions of the program provided, each showing how to do more with Word 97 from COBOL.

SOURCE FILES

=========

README.TXT

WORD1.CBL

WORD2.CBL

WORD3.CBL

WORD4.CBL

WORD5.CBL

WORDEVT.CBL

WORD97.APP

REQUIREMENTS

==========

Microsoft Word 97 should be installed.

OPERATION

=======

The demo comes in the following stages:

1. WORD1.CBL - This first demo shows how to start and stop Word from COBOL. Word will not become visible, so you need to watch the task manager to see that this works.

2. WORD2.CBL - This demo adds a new document to Word. It also shows how to make Word visible (under normal circumstances, a client program would not need to do this).

3. WORD3.CBL - This demo shows how to add text into the document, change it, and then print it out. This demonstrates how to deal with Word objects in object COBOL.

It also shows how to avoid problems with Word "timing out" on some calls by setting the COBOL OLE "Busy Timeout" value.

4. WORD4.CBL - This demo shows how to deal with exceptions (such as not having a printer installed). An exception handler is registered as a callback. The handler does nothing more than display the exception.

5. WORD5.CBL and WORDEVT.CBL - This demo shows how to capture events that Word returns. Two of the events that Word is documented to return are captured by the class wordevt.

The olesup method "adviseEvents" is invoked using the Word object and the wordevt class in order to register for events. It returns an instance of the wordevt class, which is an OLE Automation class specifically designed for receiving events.

Note that events can only occur at specific boundaries, such as OLE method calls or message processing, and that Word will wait until the demo program has received each event before accepting a new command.

To animate, right click on the .int file in the build target window, and select "Animate".

Word documents its Automation objects, properties and events in the "Microsoft Word Visual Basic Reference".

WHAT TO DO IF SOMETHING GOES WRONG

===========================

1. Make sure that all programs used in talking to Word are compiled with the option ooctrl( p). This allows the run-time to access parameter information.

2. Check that the method being called is supported by Word 97 - look in the vbawrd8.hlp help file for a complete list of Word commands. Make sure that you are using the correct command with the correct object.

==========================================================

Keywords: demonstration, sample, example, demo, word97.zip

demo.ex

demo.ne

Attachments:

word97.zip

Old KB# 4035