Wednesday, October 5, 2011

Creating a new Excel sheet, Opening the exsisting sheet & entering data and saving it

'Creating a new Excel sheet
Set xlapp = createobject("excel.application")
xlapp.Visible = true
xlapp.Workbooks.Add
xlapp.ActiveWorkbook.SaveAs("C:\Documents and Settings\pavann\Desktop\qtp12")xlapp.Application.Quit
Set xlapp=nothing

'Opening the exsisting sheet & entering data and saving it
Set xlapp1 = createobject("Excel.Application")
xlapp1.Visible = true
Set xlbook1 = xlapp1.Workbooks.Open("C:\Documents and Settings\pavann\Desktop\qtp12")Set xlsheet1 = xlbook1.Worksheets("sheet1")
For i = 1 to 10
xlsheet1.cells(i,1).value = "pavan"
For k = 1 to 10
If k>1 Then
xlsheet1.cells(i,k).value = "soumya"
End If
Next
Next
set objrange = xlsheet1.usedrange
For each cell in objrange
cell.value = ucase(cell.value)
Next
xlbook1.Save
xlapp1.Application.Quit
Set xlapp1=nothing

-- Pavankumar Nandagiri

Google Search

Google