...

View Full Version : Problem with JavaScript-VBScript and Excel programming file



manans25
06-07-2007, 05:44 PM
Hi all, I am having a problem with the following code. The font is red is where the error is coming. When I type both the lines together, it says 'Expected ;' but they work independently.

can you guys figure out the problem? I have been breaking my head on it all day!!



<HTML>
<BODY>
Press the button to start Excel and display quarterly data.

<SCRIPT LANGUAGE="VBScript">


Function RemoveSR(oXL)
' Create an array to set multiple values at once.
dim x
dim y
x=1
y=1

Do Until oXL.Cells(x,y).Value = ""
x = x + 1
loop

Dim saNames_1(9999, 18)
dim arr_xcount

arr_xcount=1

for rx = 1 to x

if oXL.Cells(rx, 8) <> "Service Request" then

for ry = 1 to 18
saNames_1(arr_xcount-1, ry-1) = oXL.Cells(rx, ry).Value

next


arr_xcount = arr_xcount + 1

end if




next

RemoveSR = saNames_1
End Function

Function CreateNamesArray(oXL)
' Create an array to set multiple values at once.
dim x
dim y
x=1
y=1
Do Until oXL.Cells(x,y).Value = ""
x = x + 1
loop

Dim saNames(9999, 18)
dim arr_xcount

arr_xcount=1

for rx = 1 to x

if oXL.Cells(rx, 8) = "Service Request" then

for ry = 1 to 18
saNames(arr_xcount-1, ry-1) = oXL.Cells(rx, ry).Value
next

arr_xcount = arr_xcount + 1

end if



next

CreateNamesArray = saNames
End Function







</SCRIPT>


<SCRIPT LANGUAGE="JScript">
function AutomateExcel()
{

// Start Excel and get Application object.
var oXL = new ActiveXObject("Excel.Application");
var oWB1=oXL.Workbooks.Open("C:\\Documents and Settings\\T_SHAHMA\\Desktop\\work_folder\\060607b.csv");
var oSheet=oWB1.ActiveSheet;
oSheet.PageSetup.Zoom=90;

oSheet.Range("A2","CM3052").Font.Bold=true;

var oSheet2=oWB1.WorkSheets.add;
oSheet2.Name="New Sheet";



oSheet.Activate;


oSheet2.Range("A2", "P9999").Value = CreateNamesArray(oXL);
oSheet2.Name="Service Requests";


var oSheet3=oWB1.WorkSheets.add;
oSheet3.Name="All Service Requests";






oSheet.Activate;
oSheet3.Range("A1", "R9999").Value = RemoveSR(oXL);
oSheet3.Name="All Service Requests";


oXL.Visible = true;
oXL.UserControl = true;






}

</SCRIPT>
<P><INPUT id=button1 type=button value="Start Excel" onclick="AutomateExcel"></P>
</BODY>
</HTML>

LFCFan
06-08-2007, 01:09 PM
oSheet.Activate;
oSheet3.Range("A1", "R9999").Value = RemoveSR(oXL);


What is RemoveSR(oXL)? Is the error occurring at this line, or if RemoveSR() is a javascript function, is the error occurring within that? Also, have you checked the value of oXL to make sure its not null/empty, or a malformed string/integer?

Also, don't know if this is a typo:


<P><INPUT id=button1 type=button value="Start Excel" onclick="AutomateExcel()"></P>

Joe

manans25
06-08-2007, 03:43 PM
RemoveSR(oXL) is a function in VBscript

I am calling RemoveSR function and passing it the excel application as parameter.

It is very similar to the manner in which ChangeNamesArry function is called and it works!

I tried everything by renaming variables but it still asks for the semicolon.

This is the line.


oSheet3.Range("A1", "R9999").Value = RemoveSR(oXL);



I don thtink oXL is null as it works for a similar fucntion before i call RemoveSR...that is ChangeNames Array.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum