Student Mode Code Display

Welcome to the Fraternity!

Commenting has been enabled. You can comment on all the Code Items now.

Excel Operations Create Read Write Count Color


Add This Code to My Favourite List
Enter Email

Contributed By Sandeep Jadhav
Date 2016-04-12 10:04:10

'Excel Operations

Dim xl, xl_workbook, xlsheet1

' Creating excel app object
Set xl=createobject("Excel.Application")
xl.Visible=true

'Create an excel file
Set xl_workbook=xl.Workbooks.Add

'add sheets
Set xlsheet1=xl_workbook.Sheets.add
xlsheet1.name="Test2"

'Enter values in sheet
'First row
xlsheet1.cells(1,1)="Name"
xlsheet1.cells(1,2)="Age"
xlsheet1.cells(1,3)="Address"
'Second Row
xlsheet1.cells(2,1)="sanjeev"
xlsheet1.cells(2,2)="25"
xlsheet1.cells(2,3)="Pune"
'Third Row
xlsheet1.cells(3,1)="midhun"
xlsheet1.cells(3,2)="25"
xlsheet1.cells(3,3)="trivendrum"
'Third Row
xlsheet1.cells(4,1)="Raj"
xlsheet1.cells(4,2)="30"
xlsheet1.cells(4,3)="Jalna"

' get no of rows occupied
rowCount=xlsheet1.usedRange.rows.count
msgbox rowCount

'get no of cols occupied
colCount=xlsheet1.usedRange.columns.count
msgbox colCount

'Set background color to each cell
        For each cell in xlsheet1.usedRange
                cell.Interior.ColorIndex=3
        Next

'Save the workbook
xl_workbook.SaveAs "D:\WORK\QTP\QTPSTUFF\Datasheet\Test2.xls"

'Close the application
xl.Quit

'Release the object
Set xl=nothing

Download Above Code

Comments:



Add your comments...
Name : *      
Email : *      
The content of this field will be kept private and will not be shown publicly

Your Comment/Answer *

Enter the text present in this box : *