Working with Excel Sheets – create, open, modify, save, close!!

‘Getting value from an existing excel sheet

Dim oExcel, oWB, oSheet, getVal
Set oExcel=CreateObject(“Excel.Application”)
Set oWB=oExcel.Workbooks.Open(“C:abhikansh.xls”)
Set oSheet=oWB.WorkSheets(“Sheet1”)
oExcel.Visible=TRUE
getVal=oSheet.Cells(1,1).Value
print getVal
oWB.Close
Set oExcel=Nothing

‘Inserting value to an existing excel sheet
Dim oExcel, oWB, oSheet, setVal
Set oExcel=CreateObject(“Excel.Application”)
Set oWB=oExcel.Workbooks.Open(“C:abhikansh.xls”)
Set oSheet=oWB.WorkSheets(“Sheet1”)
oExcel.Visible=TRUE
setVal=”ValueInserted”
oSheet.Cells(4,1).Value=setVal

oWB.Save
oWB.Close
Set oExcel=Nothing

‘Create a new excel sheet, insert values and save it..
Dim oExcel, oWB, oSheet, setVal
Set oExcel=CreateObject(“Excel.Application”)
Set oWB=oExcel.Workbooks.Add
Set oSheet=oWB.WorkSheets(“Sheet1”)
oExcel.Visible=TRUE
setVal=”ValueInserted”
oSheet.Cells(4,1).Value=setVal

oWB.SaveAs(“C:abhikansh1.xls”)
oWB.Close
Set oExcel=Nothing

3 thoughts on “Working with Excel Sheets – create, open, modify, save, close!!”

  1. Nice example. I am having trouble closing an Excel file which opens from web application. Could anyone please tell me how can I close that file. The recorded script doesn't work.

    Rosh.

  2. Hi Abhikansh, nice code working, my scenario is to save web table contents suppose the web table has 100 rows and 10 columns, Can u please let me know the code How to save those values into an external excel sheet.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top