Forum Discussion

s_sakthivel's avatar
s_sakthivel
Occasional Contributor
10 years ago

Object Id Required Error message displayed.

I have written code in GeneralEvents_OnStartTest(Sender)  for excel app. 

I have declared objects and verified name of Object and everything are correct. 



But still I am getting error message



Dim App, FileName,WorkBook,PrivateCar        



Sub GeneralEvents_OnStartTest(Sender)    

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


FileName = "C:\TC_Test Data Sheet\Product.xlsx"


Set WorkBook = App.Workbooks.Open(FileName)


Set PrivateCar = WorkBook.Sheets("Private_Car")



End Sub



On running, error message displayed as Object Id "PrivateCar" Required. 



UserId =PrivateCar.Cells(3,1)



Please help on the same.

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Perhaps I'm misunderstanding.  Is the error happening when executing the OnStartTest event handler or are you getting the error when executing your other statement:



    UserId =PrivateCar.Cells(3,1)




    If your error happens in this UserID assignment call AND that call is happening in a different script unit than where the Dim is declared, that would be the cause then.  You need to make sure that any unit of code that wants to utilize the PrivateCar variable has USEUNIT pointing to the code unit containing the Dim statement.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I'm not near a workstation where I can reproduce this at the moment.  However, if memory serves, the event handlers need to have all variables used within them called from within them.  In other words, move your Dim statement to within your sub-routine.  I'm not sure if the even handler recognizes the Dim outside of the handler code.
  • Hi Sakthivel,



    I tried your code by including DIM statements in onstart event.

    It worked fine for me.



    Thanks,

    Neha