Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

vb question

  • 07-02-2008 07:43PM
    #1
    Closed Accounts Posts: 114 ✭✭


    anyone know how to read the contents of an xls file into an array in a vb6 application? Also how do you do a file input box where the user can browse their computer to find the file they wish to insert into the form?


Comments

  • Closed Accounts Posts: 164 ✭✭ob


    I did something similar in vba, but you can probably adapt it. What this code does is populate a 2-dimensional array with the contents of the worksheet.


    Public Sub ReadIntoArray
    Dim arrContents() As String
    Worksheets("Sheet1").Activate
    Dim ArrayColumns, ArrayRows, i, j As Integer
    ArrayRows = Cells.SpecialCells(xlCellTypeLastCell).Row
    ArrayColumns = Cells(1, Columns.Count).End(xlToLeft).Column
    ReDim arrContents(ArrayRows - 1, ArrayColumns - 1)
    For i = LBound(arrContents, 1) To UBound(arrContents, 1)
    For j = LBound(arrContents, 2) To UBound(arrContents, 2)
    arrContents(i, j) = Range(Cells(i + 1, j + 1), Cells(i + 1, j + 1))
    Next j
    Next i
    End Sub


Advertisement