ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with "For each" loop using .NET Interop and Excel (https://www.excelbanter.com/excel-programming/299685-re-problem-each-loop-using-net-interop-excel.html)

Juan Pablo González

Problem with "For each" loop using .NET Interop and Excel
 
Can't test it here, but try

r = Excel.Selection

instead of just

r = Selection

--
Regards

Juan Pablo González

"Gene Belknap" wrote in message
...
Hi,

When running the following code snippet using

"Microsoft.Office.Interop.Excel" through VB.NET

dim c as Excel.Range
dim r as Excel.Range

r = Selection

For Each c in r '<-- Fails with "Member not found"
msgbox (c.Address)
Next

"For Each c in r.Cells" also fails with the same error.

In each case, I get the "Member not found" error.

I can use a loop counter successfully. For example

dim i as Integer

for i = 1 to r.cells.count
c = r.cells(i)
msgbox (c.Address)
next

this code works.

The "for each c in r" construct works fine with VBA. The problem is in

porting VBA to .NET. Without the "for each c in r" construct, the port will
be very painful and tedious.

Any reason why the "for each c in r" approach does not work in .NET? Are

there updates/patches that fix this? Am I missing something?

Thanks,

-Gene





All times are GMT +1. The time now is 09:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com