Restructure your code a bit analogous to this:
Modification:
Sorry Farah for posting untested code. This time I tried out the example I posted below and it works. So please try to resolve your issue by using the code below as an example. I removed some funny characters that were there. Instead of an o in onclick and onload there was an ö both times. I adjusted the path in my example because I had to generate an Excel workbook for the test. Please substitute your path instead, but look at what you did in your excel path. I'm not sure why you wanted to append x to the end of the filename because x would have been the excel worksheet (see your önload in the body tag).
<html>
<head>
<script type="text/javascript">
// This global variable may not really be needed, but you might want to use it later on so I made it global
var myExcelSheet = undefined;
function initialize(){
Excel = new ActiveXObject("Excel.Application");
Excel.Visible = false;
return Excel.Workbooks.Open("C:/temp/test.xlsx").sheets(1);
}
function search(sheet){
var n = sheet.usedrange.rows.count;
alert(n);
}
function onBodyLoaded()
{
// Sets the global variable myExcelSheet here
myExcelSheet = initialize();
}
</script>
</head>
<body onload="onBodyLoaded();">
<form>
<input type="checkbox" id="b1" onClick="search(myExcelSheet)">
</form>
</body>
</html>
You should really debug this using IE's "Developer Tools" where you can set breakpoints in your javascript and then go through your code step by step.
Happy coding!
-MRB