Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm trying to do the following

 


Dim xlRange As Excel.Range
Dim xlCell As Object

xlRange = xlbook.Sheets(sSheetname).Range(sRange)

For Each xlCell In xlRange.Cells
 'Do Something
Next xlCell

 

but I get a System.Runtime.InteropServices.COMException saying "Member not found" on Line For Each xlCell In xlRange.Cells

 

Any Ideas?

  • Leaders
Posted

try the UsedRange method , here's a quick example ...

       Dim exl As New ApplicationClass()
       Dim book As WorkbookClass = exl.Workbooks.Open("C:\Book1.XLS")
       Dim sh As Worksheet = book.Worksheets("Sheet1")
       Dim rng As Range = sh.UsedRange()
       Dim x As Integer, i As Integer
       For x = 1 To rng.Rows.Count
           For i = 1 To rng.Cells.Count
               MessageBox.Show(rng.Cells.Item(x, i).GetType.InvokeMember("Value", Reflection.BindingFlags.GetProperty, Nothing, rng.Cells.Item(x, i), Nothing))
           Next
       Next

       exl.Quit()

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...