Micro Focus QTP (UFT) Forums
Can we save an exported Excel sheet directly from QTP? - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Can we save an exported Excel sheet directly from QTP? (/Thread-Can-we-save-an-exported-Excel-sheet-directly-from-QTP)



Can we save an exported Excel sheet directly from QTP? - Akhila - 11-26-2013

Hi There,

I stored some values to Data table and exported them to an Excel sheet using following script
datatable.ExportSheet "C:\book.xls", "MySheet"

Now can it possible save the file book.xls in C drive... directly from QTP. If so can you please advice?

Thanks,


RE: Can we save an exported Excel sheet directly from QTP? - ssvali - 11-26-2013

You can write those values directly in Excel and Save it where you want by using QTP.

Code:
Set ObjExcel = CreateObject("Excel.Application")
ObjExcel.Visible = TRUE
Set sWorkbook = ObjExcel.Workbooks.Add
Set sWorksheet = sWorkbook.Worksheets("sheet1")

sWorkbook.Worksheets("sheet1").Cells(1,1).Value = "User Name"
sWorkbook.Worksheets("sheet1").Cells(1,2).Value = "Password"

sWorkbook.SaveAs "C:/Book.xls"

Set sWorksheet = Nothing
set sWorkbook = Nothing
set ObjExcel = Nothing



RE: Can we save an exported Excel sheet directly from QTP? - Akhila - 11-28-2013

Thanks for the solution.

Now i can save the excel file by your method of creating an excel obj.
I am also assuming that there is no way we can save the excel file from qtp when we export data from DT to Excel. If I am wrong please correct it.

Thanks,
Akhila