Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to write the code for creating excel in QTP
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
Hi Anyone Help to me how to write the code for creating excel sheet.
I have installed in MS excel 2007.

I am trying the below code and run through QTP. But excel sheet is not created the particular path

Code:
public strFullPath
strFullPath="D:\SST 1C\Results\Accommodation\Results.xls"
Function CreateExceFile()
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(strFullPath)) Then
Set objExcelApplication = CreateObject("Excel.Application")
objExcelApplication.Workbooks.open(strFullPath)
Else
Set objExcelApplication = CreateObject("Excel.Application")
objExcelApplication.Visible = true
objExcelApplication.Workbooks.Add
objExcelApplication.ActiveWorkbook.SaveAs strFullPath
End If
Set objResultSheet = objExcelApplication.ActiveWorkbook.Worksheets(1)
objResultSheet.Name = "Results"
objExcelApplication.ActiveWorkbook.Save
objExcelApplication.Workbooks.Close        
objExcelApplication.Quit
Set objExcelApplication = Nothing
End Function
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
u have written function correctly but you just forgot to call it in your code thats the reason its not working..
i have added call to your function CreateExceFile() .. now its working ..

happy scripting Smile

CreateExceFile()
Code:
public strFullPath
strFullPath="D:\SST 1C\Results\Accommodation\Results.xls"
CreateExceFile()
Function CreateExceFile()
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(strFullPath)) Then
Set objExcelApplication = CreateObject("Excel.Application")
objExcelApplication.Workbooks.open(strFullPath)
Else
Set objExcelApplication = CreateObject("Excel.Application")
objExcelApplication.Visible = true
objExcelApplication.Workbooks.Add
objExcelApplication.ActiveWorkbook.SaveAs strFullPath
End If
Set objResultSheet = objExcelApplication.ActiveWorkbook.Worksheets(1)
objResultSheet.Name = "Results"
objExcelApplication.ActiveWorkbook.Save
objExcelApplication.Workbooks.Close        
objExcelApplication.Quit
Set objExcelApplication = Nothing
End Function
Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
Hi Pavan

Thanks lot . Now it is working fine.
I wil keep you post on my clarification
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help in creating dynamic object string using Childobjects Keshub Mathur 0 1,608 09-11-2017, 05:52 PM
Last Post: Keshub Mathur
  How to write reports from scripts into excel anushreebehura 1 2,256 10-04-2016, 09:29 PM
Last Post: venkatesh9032
  HAVING PROBLEM IN CREATING OBJECT OF TEST BATCH RUNNER mayankchauhan 0 3,438 04-04-2014, 05:29 PM
Last Post: mayankchauhan
  how to find Excel file exist or not in vbscript code sree.85 3 11,253 08-22-2013, 11:42 AM
Last Post: akhandesh
  Creating a folder from within a reusable action. sd3 2 3,186 06-18-2013, 03:20 PM
Last Post: learnQtptips

Forum Jump:


Users browsing this thread: 1 Guest(s)