Forum Discussion

mesg2anil's avatar
mesg2anil
Regular Contributor
14 years ago

Using Array to get Excel data

Hi,



I'm trying to get values (data) from excel, after using if and for loop to get rows and columns details, I'm trying to put the data to an array and then use the array to input the data from array to application. Below is the code which I'm using to get the data from excel and tying to put the data into array... this the place where I'm having trouble... please help!!



Function testarray()


'Open Excel Connection


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


 Call Excel.Workbooks.Open("E:\Anil-Backup\Test Complete\Projects_Old\In4Suite Project\ExcelFile\Rental Database\RentalTermSheet.xlsx")


 Delay 1000


 


 'Read number of rows and assign it to 'i'


 i = Excel.ActiveSheet.UsedRange.Rows.Count


 j = Excel.ActiveSheet.UsedRange.Columns.Count     


 


Log.Message i   


Log.Message j


 


 If i > 1 then   


for k = 2 to i     


For l = 1 to j 


s = VarToStr(Excel.Cells(k, l)) + "#"   


 


testarray = s 


 


next 


Next 


End if   


 


Call Excel.ActiveWorkbook.Save   


Call Excel.Workbooks.Close 


End Function


 


Sub arrcells


    


Dim str, arrStr 


Str = testarray() 


arrStr=Split(Str,"#") 


Log.Message arrStr (0)


'Log.Message arrStr(1) 


'Log.Message arrStr(2) 


 


End Sub