Skip to content
This repository was archived by the owner on Aug 27, 2023. It is now read-only.

Latest commit

 

History

History
18 lines (14 loc) · 523 Bytes

File metadata and controls

18 lines (14 loc) · 523 Bytes
layout page
title Enumerating Excel COM Automation collections in VB.NET

When referencing COM Automation collections late-bound, the enumeration via For Each does not automatically work. An explicitly cast or set to a variable of type IEnumerable will work, though:

Dim app As Object = ExcelDnaUtil.Application

Dim sh As Object
Dim flg As Boolean

For Each sh In CType(app.Worksheets, IEnumerable)
    ' Do stuff with sh here
Next

This should not be needed if an interop library is referenced.