Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to write the code for creating excel in QTP
02-28-2010, 01:13 AM
Post: #1
How to write the code for creating excel in QTP

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

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

Thanks
M.V.Moorthy
Find all posts by this user
Quote this message in a reply
02-28-2010, 06:42 PM
Post: #2
RE: How to write the code for creating excel in QTP
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
Visit this user's website Find all posts by this user
Quote this message in a reply
02-28-2010, 08:16 PM
Post: #3
RE: How to write the code for creating excel in QTP
Hi Pavan

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

Thanks
M.V.Moorthy
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Output is different from two different machines for the same block of code in QTP. bdash_10 0 90 04-13-2012 03:38 PM
Last Post: bdash_10
  How to write In PDF Form using QTP anukapoor 3 488 04-05-2012 06:00 PM
Last Post: atulparate
  Creating an array from an specific field in the recordset Arena 0 196 04-04-2012 09:58 PM
Last Post: Arena
  about descriptiove programming and creating objects babukaturi 1 199 04-03-2012 01:59 PM
Last Post: sshukla12
Exclamation QTP - Code to select a link Unleash Rajesh 3 1,182 01-03-2012 06:57 PM
Last Post: prabhukrishna

Forum Jump:


User(s) browsing this thread: 1 Guest(s)