Uska
Uska

Reputation: 65

Adding Values from a excel /csv files in a text box in QTP

Adding Values from a excel /csv files in a text box in QTP

Hello All,

I have a excel file on hand from which I am trying to copy fields into a text box, the file has multiple values in multiple columns and rows. I am selecting a single row and trying to insert those values into the text box, however whenever the value is entered in the text box, the next value overwrites current value and there is only 1 value in the end. I want all values to be reflected in that text box so I can click the submit button:

Code is as follows:

Set myxl = createobject("excel.application")
myxl.Workbooks.Open "J:\Example1.csv"
myxl.Application.Visible = true

set mysheet = myxl.ActiveWorkbook.Worksheets("Example1")

'Get the max row occupied in the excel file 
Row=mysheet.UsedRange.Rows.Count
'Get the max column occupied in the excel file 
 Col=mysheet.UsedRange.columns.count
    For  i= 2 to Row
    For j= 2 to Col
        Msgbox  mysheet.cells(i,j).value
        Browser("Some site").Page("Some page").WebEdit("Text Box").Set     mysheet.cells(i,j).value + vbLf 

        j = j+7
        Next
    Next
'Save the Workbook
myxl.ActiveWorkbook.Save
'Close the Workbook
myxl.ActiveWorkbook.Close
'Close Excel
myxl.Application.Quit

Set mysheet =nothing
Set myxl = nothing

And following is the file column which I want in the text box

Column from the file I need to import in the text box

This is what happens when I run the program, First 2 values are deleted

![Original Text field I want to run and submit][3]

As you can see the text box only accepts the last value from the file and the previous 2 are deleted. I want to capture all the values from the file and put them in the text box

Thank you in advance --Umesh

Upvotes: 0

Views: 2186

Answers (1)

user2432405
user2432405

Reputation: 1414

    ...
    'Get the max column occupied in the excel file 
     Col=mysheet.UsedRange.columns.count
        For  i= 2 to Row
          For j= 2 to Col
            input = input + mysheet.cells(i,j).value + vbLf        
            j = j+7
          Next
        Next
        Browser("Some site").Page("Some page").WebEdit("Text Box").Set input
    'Save the Workbook
    ...

Upvotes: 2

Related Questions