05-12-2011, 08:17 AM
Hi
I am trying to create a function to dynamically add sheet and import data in the runtime datatable in qtp.The function is adding all sheets but not retrieving data from excel .Codes are below.Can anyone resolve the problem ?
I am trying to create a function to dynamically add sheet and import data in the runtime datatable in qtp.The function is adding all sheets but not retrieving data from excel .Codes are below.Can anyone resolve the problem ?
Code:
importdata("C:\Book1.xls")
Function importdata(filepath)
Set xlapp = createobject("Excel.Application")
Set xlbook = xlapp.Workbooks.Open(filepath)
allsheets = xlapp.Worksheets.Count
For i = 1 to allsheets
sheetname = xlapp.Worksheets(i).Name
datatable.AddSheet sheetname
datatable.ImportSheet filepath,sheetname,sheetname
Next
xlbook.Close
xlapp.Quit
Set xlapp = nothing
Set xlbook = nothing
End Function