Probably a silly vb.net question

  • Thread starter Thread starter Nicke
  • Start date Start date
N

Nicke

Hi, I've used vb.net for 3 hours(!) now and have probably
a 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 have
translated it correctly) in the For... statement.

Thanks in advance.

/Nicke
 
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
 
Keep in mind that, when you use VB.Net to talk to Office,
you are actually interacting with Excel automation using
COM Interop. The cost of crossing the managed/unmanaged
boundry might account for the slowdown you are seeing.
 
Back
Top