Sys.OleObject Property

Applies to TestComplete 14.0, last modified on January 23, 2019

Description

The Sys.OleObject property returns an OLE server by its name and the name of the machine on which it is running. To specify the OLE server running on the local machine, do not specify the MachineName parameter.

Declaration

Sys.OleObject(OleObjectMachineName)

Read-Only Property Object
OleObject [in]    Required    String    
MachineName [in]    Optional    String Default value: ""   

Applies To

The property is applied to the following object:

Sys

Parameters

The property has the following parameters:

OleObject

ProgID or CLSID of the OLE server you want to access. For example, "Word.Application" or "{000209FF-0000-0000-C000-000000000046}".

MachineName

Specifies the name of the machine on which the specified OLE server is running. To get the OLE server running on the local machine, leave the value of this parameter empty.

Property Value

An object that represents the specified OLE server.

Remarks

  • You cannot use TestComplete as a client application for in-process OLE objects, the bitness of which is different than the bitness of TestComplete.

  • TestComplete does not release instances of OLE objects created via the Sys.OleObject method at design time, that is, when this method is used to explore the object in the Object Browser or to get code completion for the object’s methods and properties. For example, creating a Word.Application object launches Microsoft Word and it keeps running after you have finished working with the object in the Object Browser or the Code Editor. To release the used OLE object instance, you need to manually close the process that the object is running in or to execute the script code that would release that object, for example:

    JavaScript, JScript

    function QuitWord()
    {
      Sys.OleObject("Word.Application").Quit();
    }

    Python

    def QuitWord():
      Sys.OleObject["Word.Application"].Quit()

    VBScript

    Sub QuitWord
      Sys.OleObject("Word.Application").Quit
    End Sub

    DelphiScript

    procedure QuitWord;
    begin
      Sys.OleObject('Word.Application').Quit;
    end;

    C++Script, C#Script

    function QuitWord()
    {
      Sys["OleObject"]("Word.Application")["Quit"]();
    }

  • Note for Microsoft Office users: In order to be able to get an OLE object for an already running application, this application must be registered in the Running Object Table (ROT). However, Microsoft Office applications that are launched from the shell (for example, from the Start menu or the TestedApps project item) do not register their running objects at startup, but rather once the application loses focus. So, if you obtain an OLE object for an already running Office application, you may get errors when accessing its properties and methods (for more information on this problem, see http://support.microsoft.com/kb/238610/).

    To work around the problem, you can activate any window other than the tested Office application before attaching to its OLE server. This will allow the Office application to register itself in the ROT, so you will be able to work with it via OLE. In scripts, you can activate a window using the Activate or Click action. For example, use the following statement to activate the Windows taskbar:

    JavaScript, JScript

    Sys.Process("Explorer").Window("Shell_TrayWnd").Activate();

    Python

    Sys.Process("Explorer").Window("Shell_TrayWnd").Activate()

    VBScript

    Sys.Process("Explorer").Window("Shell_TrayWnd").Activate

    DelphiScript

    Sys.Process('Explorer').Window('Shell_TrayWnd').Activate;

    C++Script, C#Script

    Sys["Process"]("Explorer")["Window"]("Shell_TrayWnd")["Activate"]();

    Another solution is to launch the desired Office application and work with it only using its OLE object. However, in this case you may not notice changes made to the application, because launched in this way, it is not displayed on screen initially. To make the application visible, can set the Visible property of its OLE object to True:

    JavaScript, JScript

    // Launch Excel
    var Excel = Sys.OleObject("Excel.Application");
    // Make it visible
    Excel.Visible = true;
    ...

    Python

    # Launch Excel
    Excel = Sys.OleObject["Excel.Application"]
    # Make it visible
    Excel.Visible = True
    # ...

    VBScript

    Dim Excel
    ' Launch Excel
    Set Excel = Sys.OleObject("Excel.Application")
    ' Make it visible
    Excel.Visible = True
    ...

    DelphiScript

    var Excel : OleVariant;
    ...
    // Launch Excel
    Excel := Sys.OleObject['Excel.Application'];
    // Make it visible
    Excel.Visible := true;
    ...

    C++Script, C#Script

    // Launch Excel
    var Excel = Sys["OleObject"]("Excel.Application");
    // Make it visible
    Excel["Visible"] = true;
    ...

  • As an alternative to Sys.OleObject, you can use the getActiveXObject method which is specific to JavaScript (not JScript). It significantly improves performance of OLE object scripting.

See Also

Viewing COM Object Properties, Methods and Events
NetworkSuite.GetRemoteOLEObject Method

Highlight search results