Results 1 to 5 of 5

Thread: Help reading excel file

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    5
    I've set my references.....
    heres my code:
    -----------------------------------------------------------
    Public Sub open_xls(filename As String)


    Dim xlapp As Excel.Application
    Dim xlbook As Excel.Workbook
    Dim xlsheet As Excel.Worksheet

    Set xlapp = CreateObject("excel.application")

    Set xlbook = xlapp.Workbooks.Open(filename)

    Set xlsheet = xlbook.Worksheets(1)
    morenum = 10
    ReDim numbers(0 To morenum)
    'place the value of the cells into variables
    Dim n%
    ************PROBLEM RIGHT HERE**********
    Do Until xlsheet.Cells(n, 1).Value = ""
    ************PROBLEM RIGHT HERE**********
    I want my application to read until there it hits a cell w/no value!!!!

    If n >= UBound(numbers) Then
    Dim evenmorenums%
    evenmorenums = morenum + morenum
    ReDim Preserve numbers(0 To evenmorenums)
    End If
    With numbers(n)
    .fname = xlsheet.Cells(n + 1, "a")
    .phone = xlsheet.Cells(n + 1, "b")
    n = n + 1
    End With

    Loop

    ReDim Preserve numbers(LBound(numbers) To (n - 1))

    Set xlsheet = Nothing
    Set xlbook = Nothing

    xlapp.Quit
    Set xlapp = Nothing

    End Sub


  2. #2
    Lively Member
    Join Date
    Jun 1999
    Posts
    120
    i think the problem is "n" is not initialized...
    initialize it before the loop (Do Until xlsheet.Cells(n, 1).Value = "" )

    hope this helps...

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    5

    i think the problem is "n" is not initialized...
    initialize it before the loop (Do Until xlsheet.Cells(n, 1).Value = "" )

    hope this helps...

    I initialized n right before the Do Until .........
    Dim n%........

    my problem is that I get a type mismatch for this line when i run the program

    Do Until xlsheet.Cells("n", 1).Value = ""

    how would you go about reading an excel spreedsheet????

    thanks for your help

    Will

  4. #4
    Lively Member
    Join Date
    Jun 1999
    Posts
    120
    you declared or "dimmed" it...but not
    initialized as in...

    Code:
    ' dim - to make sure, make n an integer
    dim n integer
    
    ' initialize n
    n = 1
    
    ' loop
    Do Until xlsheet.Cells(n, 1).Value = ""  
    ' there should be no quotation marks around n

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    5

    you declared or "dimmed" it...but not
    initialized as in...

    Code:
    ' dim - to make sure, make n an integer
    dim n integer
    
    ' initialize n
    n = 1
    
    ' loop
    Do Until xlsheet.Cells(n, 1).Value = ""  
    ' there should be no quotation marks around n

    Thanks i'm gonna try it out when i get home! I really appreciate it!


    Will

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width