Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Add New Worksheet

 Keywords: add worksheet workbook Excel 

Question:

How do you add a worksheet once you open Excel and create one?

Answer:

To add a new worksheet, you use the ADD method of the worksheets collection. Setup a reference to the worksheets collection then use .add
Function Add([Before], [After], [Count], [Type]) As Object
    Member of Excel.Worksheets

Here's how to add a blank workbook...
:startExcel
   ;   Start excel here
   excelxls = objectopen("Excel.Application")
   excelxls.visible = @false
   rptxls = excelxls.workbooks
   ;   add a blank workbook...
   rptxls.add
   ;   setup the sheets var...
   xsheets = excelxls.sheets
   objectclose(rptxls)
return