Forum Discussion

Anastasia02's avatar
Anastasia02
New Contributor
18 days ago

Sys.OleObject. Microsoft Office (Word, Excel)

I want to get the properties and methods of an already running Microsoft Office (Word, Excel) application.

For this I use OLE object but I get an error "This command is not available because no document is open."

I take into account what is written in the documentation:

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

This worked in TestComplete9 but doesn't work now (TestComplete15). Maybe there is some solution for this case? I use DelphiScript

1 Reply

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    I'm not able to get this to work either, if I already have Excel opened. I would expect the spreadsheet to open.

    function test4()
    {
        let Excel = Sys.OleObject("Excel.Application");
        //let Excel = getActiveXObject("Excel.Application");
        Sys.Process("explorer").Window("Shell_TrayWnd", "", 1).Activate();
        //Excel.Visible = true;
        Excel.Workbooks.Open("C:\\Temp\\Book2.xlsx");
        aqUtils.Delay(5000);
        Excel.Quit();
    }

    I suggest you open a support ticket via https://support.smartbear.com/testcomplete/message/