OLEObject

From Real Software Documentation

Jump to: navigation, search
Class (inherits from Object)

Used to automate COM servers. Use the WordApplication, ExcelApplication, and PowerPointApplication classes to automate Microsoft Office applications. OLE is supported on the Windows platform only.



Events
EventTriggered


Properties
Handle


Methods
Invoke Value
Invoke ValueArray
TypeName ValueArray2D


Constructors

OLEObject.Constructor(ProgramID as String)


OLEObject.Constructor(ProgramID as String, NewInstance as Boolean)


OLEObject.Constructor(copy as OLEObject)



Notes

By default, OLEObject will make the property assignment by value. If it encounters an error it will try by reference if the property is an object. If the optional ByValue parameter is True, the property assignment is by value (i.e., a copy); otherwise the assignment is by reference (i.e., a pointer copy). In Visual Basic, an assignment by reference is done using the Set command, but since Real Studio doesn’t provide that feature, you will need to use the ByValue parameter when you know the assignment should be by reference.

Currency types are treated as String to preserve precision.

Examples

The following example automates Internet Explorer.

Dim obj as OLEObject
Dim v as Variant
Dim params(1) as Variant

obj = New OLEObject("InternetExplorer.Application", True)
obj.Value("Visible") = True
params(1) = "http://www.realsoftware.com/"
v = obj.invoke("Navigate", params)

Exception err as OLEException
MsgBox err.message


The OLEObject class supports setting indexed properties. For example the Word.Document.Compatibility property is an indexed property. Here is an example.

Dim word As New OLEObject("Word.Application")
Dim doc As OLEObject

word.Visible = True
doc = word.Documents.Add

Dim params(1) As Variant
params(1) = Office.wdNoTabHangIndent

doc.Value("Compatibility", params) = True
// or
/doc.Compatibility(Office.wdNoTabHangIndent)=True


The following example creates a copy of the passed OLEObject using the copy constructor and opens a new Word document.

Dim word as New OLEObject("word.Application")
Dim wordcopy as OLEObject
wordcopy=New OLEObject(word)
wordcopy.Visible=True
wordcopy.Documents.Add


This example automates Microsoft Word.

Dim obj as OLEObject
Dim docs as OLEObject
Dim doc as OLEObject
Dim range as OLEObject
Dim v as Variant

obj = New OLEObject("Word.Application", True)

// make it visible
obj.Property("Visible") = True

v = obj.Value("Documents")
If v.objectvalue IsA OLEObject then
docs = OLEObject(v.objectValue)
v = docs.invoke("Add")
If v.objectValue isa oleobject then
doc = OLEObject(v.objectValue)
v = doc.invoke("Range")
If v.objectValue IsA OLEObject then
range = OLEObject(v.objectValue)
range.Value("Text") = "This is a sentence."
end if
end if
end if

Exception err as OLEException
MsgBox err.message


See Also

ExcelApplication, Office, OLEContainer, OLEParameter, PowerPointApplication, WordApplication classes; OLEException error.

Personal tools