Forum Discussion

anhvu's avatar
anhvu
Frequent Contributor
9 years ago
Solved

how to solve error for open excel "workbooks is null or not an object" when open excel?

I got runtime error when tried to write data to excel. This error is happened sometimes and I dont' know how to fix it.

Some times it works as expected some time no.

 

function writeAppFocusTimeResult(excelfile,sheetName,compareresult,row,column)//ac_OFF_1,ac_ON_1,ac_OFF_2,ac_ON_2,ac_OFF_3,ac_ON_3,ac_OFF_4,ac_ON_4,ONtime1,ONtime2,ONtime3,ONtime4,OFFtime1,OFFtime2,OFFtime3,OFFtime4)
{

var app = Sys.OleObject("Excel.Application");
var book = app.Workbooks.Open(excelfile);
var sheet = book.Sheets(sheetName);

app.DisplayAlerts = false;
//Write Data
// compare

sheet.Cells(row,column) = compareresult;


book.Save();
app.Quit();

}

  • anhvu's avatar
    anhvu
    9 years ago

    Hi,

     

    Thank you for your information.

     

    when debugging, it worked like a CHAMP. But when runing, sometimes I got that error. In my scripts I have to write test result for every test cycle and every time I run the test, I have to run around 100 cycles. Sometimes, I got that issue; however, I have write one more script to make sure every time I open and close the Excel, it must close successfully. and it works fine for me know.

     

     

2 Replies

    • anhvu's avatar
      anhvu
      Frequent Contributor

      Hi,

       

      Thank you for your information.

       

      when debugging, it worked like a CHAMP. But when runing, sometimes I got that error. In my scripts I have to write test result for every test cycle and every time I run the test, I have to run around 100 cycles. Sometimes, I got that issue; however, I have write one more script to make sure every time I open and close the Excel, it must close successfully. and it works fine for me know.