Thank you Bruce!
It wasn't the Add (I had that in the original code). It
was "Worksheets.Item(1)" that was missing so I changed it
to "For Each Cell In xl.ActiveSheet.Range("A1:C4")" and
it worked... I think I have a little to do before my
program is upgraded to .net...
BTW, I tested a similar code but with a much larger range
(5000 rows, 1 column). VB6 did the code in 2.5 sec
and .net in 15 sec!!! I was hoping on a speed enhancment.
Thanks for the help.
/Nicke
-----Original Message-----
I believe the problem is that you need to open or add a
Workbook before the Range method has any meaning. I
usedthe following code to get rid of the error that you were
having.
Dim xl As Excel.Application = New Excel.Application
Dim cell As Excel.Range
xl.Workbooks.Add()
For Each cell In xl.Worksheets.Item(1).Range("A1:C4")
Console.WriteLine("Value: " & cell.Value)
Next
Hope this helps
Bruce Johnson
http://www.ObjectSharp.com/Bruce
-----Original Message-----
Hi, I've used vb.net for 3 hours(!) now and have
probablya very easy question. In my VB6 programs I use For Each
Cell in Range... very often which not seems to work in
vb.net.
Ex.
Dim Cell As Excel.Range
Dim xl as Excel.Application
xl = New Excel.Application
For Each Cell In xl.Range("A1:C4")
What is wrong here? I get "Unknown interface" (if I
havetranslated it correctly) in the For... statement.
Thanks in advance.
/Nicke
.
.