Accessing Cells in an Excel Range

krinpit

Active member
Joined
Jul 31, 2003
Messages
33
Location
Dublin
Im trying to do the following

Code:
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?
 
try the UsedRange method , heres a quick example ...
Code:
        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()
 
Back
Top