XLSetCell gives error when using a variable for row

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
epreud
Newbie
Posts: 3
Joined: Wed Jan 26, 2011 10:28 pm
Location: Bristol, Connecticut

XLSetCell gives error when using a variable for row

Post by epreud » Wed Jan 26, 2011 10:42 pm

I'm trying to add data on a new row in Excel 2010, Win 7. Smoehow, the commented line below using XLSetCell (where the row is set to 4 using a litteral) works. but the line above it, that uses the variable NewRow results in OLE error 800A03EC. I tried using %NewRow% also. Same error. stepping through the code, NewRow is being set to 4 as exepcted. What's going on? are variable not supported for specifying the row to edit? is it a defect? We are evaluating, and I'm trying to sell this product to upper management, by doing a demo... Arghh!

Thanks
Eric

Let>totalPDFTime = 5.5
XLOpen>h:\MacroScheduler\PDFLoadTimeResults.xlsx,0,xlBook
XLGetSheetDims>xlBook,Sheet1,nRowCount,nColCount
Let>NewRow = %nRowCount% + 1

XLSetCell>xlBook,Sheet1,NewRow,1,totalPDFTime,scResult
//XLSetCell>xlBook,Sheet1,4,1,totalPDFTime,scResult

XLSave>xlBook,h:\MacroScheduler\PDFLoadTimeResults.xlsx
XLQuit>xlBook

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jan 26, 2011 11:03 pm

I don't have Win 7 or Excel 2010 to test with but I do see that you have spaces in your code. Remove the spaces and see if that helps.

Code: Select all

Let>totalPDFTime=5.5
XLOpen>h:\MacroScheduler\PDFLoadTimeResults.xlsx,0,xlBook
XLGetSheetDims>xlBook,Sheet1,nRowCount,nColCount
Let>NewRow=%nRowCount%+1
XLSetCell>xlBook,Sheet1,NewRow,1,totalPDFTime,scResult
//XLSetCell>xlBook,Sheet1,4,1,totalPDFTime,scResult
XLSave>xlBook,h:\MacroScheduler\PDFLoadTimeResults.xlsx
XLQuit>xlBook
With spaces removed it works for me in Xp and excel 2007.
Last edited by JRL on Wed Jan 26, 2011 11:13 pm, edited 1 time in total.

epreud
Newbie
Posts: 3
Joined: Wed Jan 26, 2011 10:28 pm
Location: Bristol, Connecticut

Post by epreud » Wed Jan 26, 2011 11:12 pm

Thanks, but no. It's not a problem with just having a few lines with no code.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jan 26, 2011 11:16 pm

Not referring to the blank lines... its the spaces in the line.

Code: Select all

Let>NewRow = %nRowCount% + 1 
Should be

Code: Select all

Let>NewRow=%nRowCount%+1 
Or you could use the MS "IgnoreSpaces" variable. At the start of your code add the line.

Code: Select all

Let>IgnoreSpaces=1

epreud
Newbie
Posts: 3
Joined: Wed Jan 26, 2011 10:28 pm
Location: Bristol, Connecticut

Post by epreud » Wed Jan 26, 2011 11:27 pm

Yes, you were absolutely correct. I also heard back from Tech support and they said the same thing. And sure enough that fixed it. Sorry I misread your answer.I'm new to this test tool and I'm not used to languages were you can't have spaces... Thanks much!
Eric

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jan 26, 2011 11:31 pm

No problem, glad you got it.

Its not that you "can't" use spaces in a line of code. Its just that if that's how you want to write, you must use the IgnoreSpaces variable.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts