>I need to transfer some data to Excel
>and I'm having problems to define the number of
>Worksheets a workbook contains.
>
>I use this code:
>oExcel = CREATEOBJECT("Excel.Application")
>oExcel.SheetsInNewWorkbook = 4 && Problem in Excel 97
>
>In Excel 2K it works fine, but in Excel 97 it returns:
>OLE error code 0x80010105 The server emited an exception
>is it a bug, is there a workaround, then I want to be sure
>that the are enough Worksheets to work.
>
>I know that I can add a new worksheet, but how can I know
>how many sheets are in the workbook before open the necessary
>worksheets ?
>
>TIA
>
>Peter
Works fine for me, I tested on Excel 97 SR-2. You can find out how many worksheets there are in the current workbook by looking at the Count property of the sheets collection:
? oExcel.ActiveWorkbook.Sheets.Count
If there aren't enough then you can Sheets.Add() to the workbook. HTH