Understanding OLE Automation

OLE Automation

OLE Automation for WordPerfect is a flexible and powerful feature you can use to quickly build applications that use WordPerfect components. OLE Automation is an integration standard that has developed to allow applications to “expose” their programmable objects so that other applications can access them. The exposed commands become an extension of the controlling programming language.

Applications that support OLE Automation are called OLE Automation servers. Programming applications that can use a server’s scripting or macro commands are called OLE Automation controllers.

As shown in the following diagram, an OLE Automation server application exposes its programmable objects to the OLE Automation controller. The OLE Automation controller incorporates the server application’s scripting or macro commands as part of its own language. The controller can send these commands back to the server.

WordPerfect Office ole Understanding OLE Automation

This is a diagram of a OLE Automation server application.

You can use OLE Automation for long and complicated manual processes that transfer data between two or more applications. For example, you may have a manual process that puts data into a spreadsheet to be used to create a presentation graphic. The graphic is used in a word processing application. If you use OLE Automation, you may be able to create a program that automatically does these steps for you. OLE Automation gives you almost total control over a variety of different applications, letting you build the applications you need through its seamless integration capabilities.

At a basic level, you can think of OLE Automation as a way for applications to speak to and control each other through their own scripting or macro programming languages. For example, you could have WordPerfect speak to and control Microsoft Word, another OLE Automation server. Because WordPerfect, in this case the OLE Automation controller, is a desktop publishing application and does not know about the inner workings of Microsoft Word, the OLE Automation server, it needs a way to get information from the server.

Conversely, WordPerfect can be controlled by other OLE Automation applications through its PerfectScript application commands and a programming language. Some of the most widely used programming languages can support OLE automation, including Microsoft Visual Basic, Microsoft Visual Basic for Applications, and C++.

WordPerfect, PerfectScript, and OLE Automation

If you have ever used a script to send commands to WordPerfect or another Corel application, you’ve used OLE Automation. When you run a script that sends commands to a Corel application, you must use the WithObject statement to enable a programmable object in the application.

Any Corel application, including WordPerfect, that supports OLE Automation provides one programmable object that allows the PerfectScript controller to send it commands. The Microsoft Visual Basic GetObject command, for example, cannot be used to access a Corel document. Additionally, Corel applications do not support properties and methods. The only way to access a Corel document through OLE Automation is by using PerfectScript application commands.

You can also use other scripting languages to call Corel OLE Automation applications. For example, you can call the WordPerfect object using a script created in Visual Basic. The following Visual Basic script creates a new WordPerfect document and inserts a footnote.

  Private Sub Form_Load()    Dim objWP As Variant    Set objWP = CreateObject(“WordPerfect.PerfectScript”)    objWP.FootnoteCreate    objWP.Tab    objWP.Type “This was inserted with VB.”    objWP.Quit   End Sub   

As in the example above, the Microsoft Visual Basic commands, or any other OLE automation application commands, must be preceded by an application name and a period.

Other OLE Automation controllers

Rather than using only PerfectScript, you can use other applications as your OLE Automation controller. For example, you can use Microsoft Visual Basic, Microsoft Visual Basic for Applications, or Microsoft C++ as your OLE Automation controller for Corel applications. However, if you use a programming language other than PerfectScript to send commands to Corel applications, you cannot use PerfectScript programming statements and functions such as FOR...NEXT or MESSAGE, or Corel dialog box definition statements; you can only use the Corel application commands.

For information about commands and functions and PerfectScript OLE Automation overviews, see the online Help in the respective application. However, it does not provide procedural and reference information about programming by using OLE automation controllers other than PerfectScript. For more information about other OLE automation controllers, see the following reference sources:

Microsoft Visual Basic Programmer’s Guide
Microsoft Windows Developer’s Kit
Microsoft Office Developer’s Kit

The PerfectScript command Quit is specifically for use with OLE Automation. If you are scripting languages such as Visual Basic, C, C++, Delphi, FoxPro, and Corel Script, you should use the Quit command at the end of the script. Because WordPerfect hosts VBA, the Quit command should not be used from VBA.

Understanding OLE Automation