Omnis Technical Note TNNO0004
OLE Automation Notation
For Omnis Studio 2.0 or above
By Omnis Environment Engineering
I've heard that Omnis Studio supports OLE Automation,
but how do I use it?
OLE Automation is fully supported in Omnis Studio 2.0 using a non-visual
component, an object that can
be instantiated via an Omnis object variable, and if necessary, without
the need for a window or report instance. Automation is described in detail
in Chapter 9 of the Omnis Programming
manual, available with Omnis Studio 2.0. This tech note
accompanies an example library that uses Automation with Microsoft
Excel, Word®, and PowerPoint®
(the PowerPoint example is available on the Omnis Studio 2.0 CD in the
Examples Browser). Download the library; the
Word example also requires a sample document.
To use this library you'll also need the latest version of the OLE Automation
component which
is on the Studio 2.0.1 CD, or Studio 2.0 users should download
it here (place it in the XCOMP folder).
Both the library and new component should only be used with Omnis Studio
2.0.
You create an automation object by declaring an Omnis object variable
and specifying the appropriate subtype, depending on what is available
on your system. When you declare the object variable in the method editor
you specify the Type as Object and the Subtype as the type of Automation
object you require. To do this click in the Subtype box in the method
editor, open the External Objects group in
the Select Object dialog, then open the Automation group and scroll the
list of available objects.
In the example library the object variables and code samples are
placed in the AutomationCode code class In the PowerPoint'97 method the
objPowerPoint object variable has the subtype 'PowerPoint.Application.8'.
Having declared your variable you can execute methods and notation against
the variable to instantiate and manipulate the object. To instantiate
a PowerPoint automation object, you can use the following method, as shown
in the example library.
; objPowerPoint is an object variable with
; subtype 'PowerPoint.Application.8'
Do objPowerPoint.$createobject()
; Starts PowerPoint object
Do objPowerPoint.$visible.$assign(kTrue)
; Makes PowerPoint visible
Do objPowerPoint.$presentations Returns objPresentations
; Obtains presentations object
Do objPresentations.$xadd() Returns objPresentation
; Adds a new presentation
; $xadd() is a method of the presentations object
For iPageNum from 1 to 5 step
;loop to add multiple slides to presentation
Do objPresentation.$slides Returns objSlide
; Obtains slides object
Do objSlide.$xadd(iPageNum,1) Returns objCurSlide
; Adds a new slide
; and so on...
; objPresentations, objPresentation, objSlide, and
; objCurSlide are all object variables with no subtype
Every Automation object has the $createobject() method together
with its own properties and methods which you can use in your code to
manipulate the object. You can examine these properties and methods at
runtime using the Omnis Interface Manager. To examine the properties and
methods of the Powerpoint object you can set a breakpoint immediately
after the $createobject() method, run the example from the main window,
then in the method editor right-click on the objPowerPoint object variable
and select the Interface Manager option from the context menu. The Interface
Manager lists the properties and methods for the object, including the
parameters and a description for each method. You'll also need to look
at the MS-VBA help file for PowerPoint, Word, or Excel for a description
of these properties and methods. The easiest way to open the help files
is to load the appropriate MS application, load the Visual Basic editor
by selecting Tools/Macros/VisualBasic Editor. When the VB editor loads,
select the Help from the menu and look for the Visual Basic Reference
for that tool. Alternatively, load the appropriate help file direct from
your MS Office folder.
In the PowerPoint example step through the code and examine the properties
and methods for each object created including the objPresentations, objPresentation,
objSlides, and objCurSlide objects. Switch to PowerPoint after each method
to see the results. The PowerPoint example creates five slides and specifies
the text and style for each. The code examples and methods for all the
examples are well commented so it should be clear what is happening in
each method.