Friday, April 9, 2010

VBScript - How Can I Add Additional Worksheets to an Excel Workbook?

VBScript - How Can I Add Additional Worksheets to an Excel Workbook?

This script adds the nine new worksheets directly after worksheet 1 (thus pushing sheets 2 and 3 to the end of the collection):

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
Set colSheets = objWorkbook.Sheets

colSheets.Add ,objWorksheet,9

[Via]