Forum Discussion

daniel_dahlin's avatar
daniel_dahlin
New Contributor
11 years ago
Solved

Microsoft VBScript runtime error when working with running instanse of excel file

I'm working on automation script which download an excel file from our web site, and then verify numbers in it.



So, the script clicks on download button, then clicks on Open button on "Open file" dialog. (note, the downloaded excel  file wasn't saves on a harddisk, it was just opened directly  without saving).



Once the excel spreadsheet opens, the script creates  OleObject for manipulating with excel file.

 Set ex = Sys.OleObject("Excel.Application")

  strSearchString =  ex.ActiveWorkbook.ActiveSheet.Range("B4")

But once the script reaches the second line it's throwing the runtime error :

"Object required: ex.ActiveWorkbook"



But,  If the script is resumed from a failing point, it passes, no errors.

If there is any solution to run it  in one full run but passes if run it again from a failing point.



Please advise,

Thanks
  • Hi,



    Your problem sounds like the one mentioned in the 'OleObject Property' help topic:

    Quote:

    ===================

    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:



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

    ===================



    Does it help?


3 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi,



    Your problem sounds like the one mentioned in the 'OleObject Property' help topic:

    Quote:

    ===================

    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:



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

    ===================



    Does it help?


  • Great,  I just added a simple click to the windows taskbar and it really solved  the problem.

    Thanks a lot.
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Cool!
    Nice to know that it helped. Thank you for the update.