Pages

Thursday, March 3

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.visible=True
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
oWB.Save
oWB.Close
Set oExcel=Nothing

7 comments:

  1. Its good, can u also explain the procedure for deleting a sheet... :)

    ReplyDelete
  2. How to add 'n' number of sheets in excel using qtp

    ReplyDelete
  3. use for loop for n number of sheets

    ReplyDelete
  4. hi i want to save the runtime data table in to my local drive.. can u pls let me know the procedure

    ReplyDelete
  5. I аm really glad tto glane at this weblo poѕts which consiѕts of tonjs of useful information, thаnks for proѵiding tһeѕe dаta.
    If you need info on msnhotmailsignin

    ReplyDelete
  6. Good job in presenting the correct content with the clear explanation.
    1337x unblock

    ReplyDelete