Working with Excel Sheets – Add new sheet

‘This code demonstrate how to add new sheet to existing excel file and rename it at runtime

Dim oExcel, oWB, oSheet, getVal
Set oExcel=CreateObject(“Excel.Application”)
oExcel.DisplayAlerts = False   ‘this will not allow alerts to be displayed
Set oWB=oExcel.Workbooks.Open(“C:abhikansh.xls”)
Set oSheet1=oWB.Sheets.Add  ‘a new sheet is added with default name i.e. Sheet4 etc.

oSheet1.Name=”QTPSchools”  ‘rename newly added sheet
oSheet1.cells(1,1).value=”Welcome”  ‘enter value
Set oExcel=Nothing

5 thoughts on “Working with Excel Sheets – Add new sheet”

Leave a Comment

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

Scroll to Top