PDA

Click to See Complete Forum and Search --> : Help reading excel file


wfs1979
Mar 27th, 2000, 06:31 AM
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

KenX
Apr 4th, 2000, 01:48 PM
i think the problem is "n" is not initialized...
initialize it before the loop (Do Until xlsheet.Cells(n, 1).Value = "" )

hope this helps...:)

wfs1979
Apr 4th, 2000, 09:23 PM
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

KenX
Apr 5th, 2000, 09:42 AM
you declared or "dimmed" it...but not
initialized as in...



' 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



:)

wfs1979
Apr 5th, 2000, 07:55 PM
you declared or "dimmed" it...but not
initialized as in...



' 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