求VB中与EXCEL表连接,从EXCEL表中读数据,数据在EXCEL中是矩阵的形式,在VB中是二维数组。高手们帮帮忙吧

解决方案 »

  1.   


    Option Explicit
    Dim ex As Excel.Application
    Dim wb As Excel.Workbook
    Dim sh As Excel.WorksheetPrivate Sub Form_Load()
    On Error GoTo err1
    Set ex = New Excel.Application
    Set wb = ex.Workbooks.Open("C:\Documents and Settings\yong.ZZY\桌面\book1.xls")
    Set sh = wb.Sheets(1)
    Debug.Print sh.Name
    Dim arr(1, 1)
    Dim i As Integer, j As Integer
    For i = 1 To 2
        For j = 1 To 2
            arr(i - 1, j - 1) = sh.Cells(i, j).Value
            Debug.Print arr(i - 1, j - 1)
        Next j
    Next iExit Sub
    err1:Set sh = Nothing
    Set wb = Nothing
    Set ex = Nothing
    Debug.Print Err.Description
    End SubPrivate Sub Form_Unload(Cancel As Integer)Set sh = Nothing
    Set wb = Nothing
    Set ex = NothingEnd Sub
      

  2.   

    忘了关闭了
    wb.Close
    ex.Quit
      

  3.   


        Dim strFileName As String
        strFileName = GetExcelFileName("客户资料表", dlg)
        
        Dim objApp As New Excel.Application
        Dim exBook As Excel.Workbook
        Dim exSheet As Excel.Worksheet
        
        Set exBook = objApp.Workbooks.Open(strFileName)
        Set exSheet = exBook.Worksheets(1)
        //存放在varCustomerList中
        Dim varCustomerList As Variant
        
        varCustomerList = exSheet.UsedRange.Value
      

  4.   

    http://blog.csdn.net/vbman2003/archive/2007/10/25/1843645.aspx