Unified Functional Testing Practitioners Forum
Showing results for 
Search instead for 
Do you mean 

Substring Out of Range in qtp script

SOLVED
Go to Solution
Respected Contributor

Substring Out of Range in qtp script

Hi,

 

 I am new to QTP.

 

I have developed the below script ,and  when I tried to run the below script, getting  error as  "substring out of range" for  Number.xlsx(see the atttached)

Bascillay I am  trying to do paramerization using excel for  addition of 2 numbers.

 

Could  some one please guide me on the below 2  questions.

1.Is my script is correct?

2.Why I am getting  substring out of range"

 

 

***************************Script********************************************

Dim worksheet,Num1,Num2

Set myxl = createobject("excel.application")
 
myxl.Workbooks.Open "C:\Number.xlsx"
myxl.Application.Visible = true

set mysheet = myxl.ActiveWorkbook.Worksheets("Number.xlsx")

Row=mysheet.UsedRange.Rows.Count
 
For i= 2 to Row
 
Num1=mysheet.cells(i,1).value
Num2=mysheet.cells(i,2).value
 
wait 1

 R= Num1 * Num2

Msgbox("Result is  :  "  & R)
 
Next
 
'Close the Workbook
myxl.ActiveWorkbook.Close
 
'Close Excel
myxl.Application.Quit
 
'Release the objects
Set mysheet =nothing
Set myxl = nothing

 

 

***************************Script********************************************

 

5 REPLIES
HPE Expert

Re: Substring Out of Range in qtp script

[ Edited ]

Hi,

 

     I am not able to see the attached.

     what line is showing the error?

     

 

Best Regards

 

If you have a valid contract with HP feel free to visit our FT/QTP Support Customer Forums: <<http://h30499.www3.hp.com/t5/Functional-Testing-QTP/ct-p/sws-Fun_Test >>
You can create an accout with your HP credentials.

Respected Contributor

Re: Substring Out of Range in qtp script

Hi,

 

Error is  getting  @ this line set mysheet = myxl.ActiveWorkbook.Worksheets("Number.xlsx")

 

I have attached the xls sheet.

 

Thanks,

Raj

 

Occasional Advisor

Re: Substring Out of Range in qtp script

Error is at line
set mysheet = myxl.ActiveWorkbook.Worksheets("Number.xlsx")
"Number.xlsx" is not a worksheet , instead it is the file name
Sheetname can be refereed by sequence no 1 ,2 3 etc or with Sheetname.
By default each excel comes with 3 sheets so if you are trying to refer data in sheet1 the line will be

set mysheet = myxl.ActiveWorkbook.Worksheets("Sheet1")
Regards:
Shruti Sagar Mishra
Software QA Analyst
################
Please Mark kudos on left , if this answers your question
################
Respected Contributor

Re: Substring Out of Range in qtp script

Hi Shruthi,

 

Thank You so  much!   I will let you know the  Results!

 

 

Thanks,

Raj

Highlighted
Occasional Advisor

Re: Substring Out of Range in qtp script

For more information on the same please have a look on below

http://softwaretestingperfection.blogspot.com/2013/09/excel-handling-in-qtp.html
Regards:
Shruti Sagar Mishra
Software QA Analyst
################
Please Mark kudos on left , if this answers your question
################