Data Driven Testing using Excel Sheet instead of datatable

This is script for data driven using excel sheet.
In this script we are not importing excel sheet to datatable.Directly values are supplied to application from excel sheet.

set ex= CreateObject("Excel.Application")

Set a=ex.Workbooks.open("D:\excel.xls")

Set b=a.worksheets("Sheet1")

dim login,pwd
for i=1 to 3
login=b.Cells(i,"A").value
pwd=b.Cells(i,"B").value
msgbox login
msgbox pwd

next

"D:\excel.xls" is path of excel sheet.
"sheet1"indicates sheet name in which values are present.
A,B are column names in excel sheet.

we have excel sheet with values as shown below in d drive.

A B
1 2
3 4
5 6

Data Driven Testing using Notepad instead of datatable

4 comments:

Anonymous said...

Hi,
I've a question: What if I don't need all the rows in the excel sheet but some rows matching a criteria. Can you please help me with the code? Also how can I create an array of all the matching rows in excel sheet. Can you please help me with this too. Thanks a ton in advance.

Anonymous said...

I have a problem in opening a excel file.
Following code is used to read input data from excel:
1. Set objExcel = createobject ("Excel.Application")

2. objExcel.visible = true

3. Set objWorkbook = objExcel.WorkBooks.Open("D:\InputData.xls")

4. Set objDriverSheet = objWorkbook.Worksheets("Sheet1")

5.msgbox objDriverSheet.Cells(1,"A").Value

When i run this, i get following Run error

'D:\InputData.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.

If you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted.
-----------------------------------
I have verified the filename and there is no mismatch.

Problem is, it is not opening the specified excel file.

Please let me know what could be the problem and suggestions.

Anonymous said...

Very helpfull code base ..truely good

Anonymous said...

Your input file format will be wrong it should be D:\InputData.xlsx

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge