Forum Discussion

prasant87's avatar
prasant87
New Contributor
13 years ago

Passing Object Full Name through Excel

Hi,

I am trying to implement an excel data driven test script and getting an error while performing any operation on objects passed from excel sheet.



Below is a edited code and I will explain the concept and error as commented line -




Sub ExcelData





  Dim Obj,excel,workbook,sheet,var,Path

 

  Path="D:\Project\Testcases.xls"

  Set excel=CreateObject("Excel.Application")

  excel.visible = True

  

  Set workbook=excel.workbooks.open(Path)

  Set sheet=workbook.worksheets("Test_Script")

 

  Set Obj=sheet.cells(4,"C") ' Excel sheet cell contains Full Name of the object copied after spying

  Obj.Click 'This line gives an error


    

  Set Obj=nothing

  Set sheet=nothing

  Set workbook=nothing

  Set excel=nothing





End Sub




Instead of code line 

 Set Obj=sheet.cells(4,"C") ' Excel sheet cell contains Full Name of the object copied after spying

  Obj.Click 'This line gives an error



if I use below hard coded script it works -



 Set Obj=Obj_Full_Name_Spied_using_Test_Complete

 Obj.Click



But, I want to pass Object Property Name as parameter and then generalize the tests based on that.



Your immediate response is highly appreciated.



P.S. Attached is the error message.



Thank you

Prasant
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The reason being is that what is returned by the object and the cell call is not the application object, but simply a string.  You need to convert that string to an object.  Try using "Eval" on the results to return the actual object before you call "Click"
  • prasant87's avatar
    prasant87
    New Contributor
    Thank a lot.



    The below code worked -

    Set Obj=Eval(sheet.cells(4,"C")) 



    Cheers !!!

    Prasant
  • prasant87's avatar
    prasant87
    New Contributor
    Thanks a lot.



    Below code worked -



    Set Obj=Eval(sheet.cells(4,"C")) 



    Cheers !!!

    Prasant