Delphi, What do I do about "no GetEnumerator present" error when using a for loop over Excel Interop

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-03-15T16:53:52Z Indexed on 2010/03/15 17:09 UTC
Read the original article Hit count: 302

Filed under:
|
|
|

Hello,

I'm trying to write a Delphi program that will loop through each worksheet in an Excel file and format some cells. I'm receiving an error while trying to use the for-in loop over the Workbook.Worksheets collection, though. The error is specifically:

[DCC Error] Office.pas(36): E2431 for-in statement cannot operate on collection type 'Sheets' because 'Sheets' does not contain a member for 'GetEnumerator', or it is inaccessible

The line of code this occurs for is:

for Worksheet in Workbook.Worksheets do

The definition of Worksheet and Workbook is as follows:

var ExcelApp: ExcelApplication;
var Workbook: ExcelWorkbook;
var Worksheet: ExcelWorksheet;

I'm porting this code to Delphi from C#, in which it works. Does anyone know why I'd be getting this GetEnumerator error? I'm using the Office 2007 Excel Interop file and Embarcadero® Delphi® 2010 Version 14.0.3593.25826.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about delphi

Related posts about excel