Welcome, Guest. Please login or register.
Login with username, password and session length

 
Advanced search

18120 Posts in 4741 Topics- by 31743 Members - Latest Member: suuraj
 

Pages: [1]   Go Down
Print
0 Members and 1 Guest are viewing this topic.
Author Topic: Want to create Excel and fill it!!    (Read 163 times)
punj prakash
User
*
Offline Offline

Posts: 11


« on: February 06, 2010, 03:24:38 PM »

I used below code , as given in the user guide of QTP , but its giving "General error" on 2nd line.

Dim ExcelSheet
Set ExcelSheet = CreateObject("Excel.Sheet")'giving General error
' Make Excel visible through the Application object.
ExcelSheet.Application.Visible = True
' Place some text in the first cell of the sheet.
ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1"
' Save the sheet.
ExcelSheet.SaveAs "C:\DOCS\TEST.XLS"
' Close Excel with the Quit method on the Application object.
ExcelSheet.Application.Quit
' Release the object variable.
Set ExcelSheet = Nothing
Logged
Asiq Ahamed
Moderator
Sr. User
*****
Offline Offline

Posts: 459



WWW
« Reply #1 on: February 06, 2010, 07:37:07 PM »

Hi Prakash,
        What you have written is correct, but MS excel application should be opened before you create Set ExcelSheet = CreateObject("Excel.Sheet") object.

Code
GeSHi (qtp):
Set ExcelObj=CreateObject ("Excel.Application")

Dim ExcelSheet

Set ExcelSheet = CreateObject("Excel.Sheet")

' Make Excel visible through the Application object.

ExcelSheet.Application.Visible = True

' Place some text in the first cell of the sheet.

ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1"

' Save the sheet.

ExcelSheet.SaveAs "C:\Documents and Settings\Desktop\TEST.XLS"

' Close Excel with the Quit method on the Application object.

ExcelSheet.Application.Quit

' Release the object variable.

Set ExcelSheet = Nothing

Set ExcelObj=Nothing

 
Created by GeSHI 1.0.7.20
Logged
punj prakash
User
*
Offline Offline

Posts: 11


« Reply #2 on: February 07, 2010, 12:41:46 AM »

Thanks Smiley
Logged
punj prakash
User
*
Offline Offline

Posts: 11


« Reply #3 on: February 07, 2010, 12:58:35 AM »

Can you tell me why is it happening?We have made ExcelObj object , but did not use it.( eg
In ExcelSheet.ActiveSheet.Cells(1,1).Value ,Activesheet method support directly ExcelSheet object. why we had to create Application (ExcelObj)object for ExcelSheet.Application.Visible.It should work directly.

Please clarify ...thanks!
Logged
Asiq Ahamed
Moderator
Sr. User
*****
Offline Offline

Posts: 459



WWW
« Reply #4 on: February 07, 2010, 02:45:36 AM »

Hi Prakash,
        This is simple,

Set ExcelObj=CreateObject ("Excel.Application")-For MS Excel Application.
Set ExcelSheet = CreateObject("Excel.Sheet")-For Sheet, not for the application.

We cannot create sheet object unless the application object is created/invoked. You can also distinguish these objects using Application.Visible property.

ExcelSheet.Application.Visible = True'Here your sheet will be visble on excel application

ExcelObj.Application.Visible = True'But here excel application will be visible not your sheet.

Hope this clarifies you!
Logged
Pages: [1]   Go Up
Print
Jump to: