Monday, 8 August 2011

how to create excel file and add sheets to it in QTP?

Set suitExcelobj= CreateObject("Excel.Application")
Set myFSO = CreateObject("Scripting.filesystemobject")
If myFSO.FileExists("C:\Testdata.xls") Then
    msgbox "file found"
    Set suitExcelWorkbook=suitExcelobj.Workbooks.Open("C:\Testdata.xls")
Else
    msgbox "file not found"
    Set suitExcelWorkbook=suitExcelobj.Workbooks.Add()
    suitExcelWorkbook.saveas("C:\Testdata.xls")
End If
   
    Set suitExcelWorkSheet=suitExcelWorkbook.Worksheets(1)
    suitExcelWorkSheet.name="Scenario1"

suitExcelWorkbook.close()
set suitExcelWorkbook=nothing
Set suitExcelobj=nothing

No comments:

Post a comment