这是一个老问题,你查以前的贴子,可以找到答案.

解决方案 »

  1.   

    这是我以前的拙作,这是其中一部分有关于读取EXCEL表格中数据的代码,你整理一下吧,应该有用的.
    Private Sub Form_Load()
        On Error GoTo NoExl
            MsgBox "处理需要一定时间,请在按“确定”后稍等。"
            
            TePath = MainForm.Text1.Text
            Set TEdata = OpenDatabase(TePath + "\LoadTemp.mdb")
            Set TEreco = TEdata.OpenRecordset("zlsmall", dbOpenDynaset)
            
            'lb2是msfelxgrid控件
            LB2.Rows = 1
            LB2.RowHeightMin = 270
            ISPas = False
            OKDO = False
            OKDO = True
            Dim i As Integer    Dim excel_app As Object
        Dim excel_sheet As Object
        Dim new_value As String
        Dim row As Integer        DoEvents
        
            ' Create the Excel application.
            Set excel_app = CreateObject("Excel.Application")
        
            ' Uncomment this line to make Excel visible.
        '    excel_app.Visible = True
        
            ' Open the Excel spreadsheet.
            excel_app.Workbooks.Open FileName:="c:\loadme.xls"
        
            ' Check for later versions.
            
            If Val(excel_app.Application.Version) >= 8 Then
                Set excel_sheet = excel_app.ActiveSheet
            Else
                Set excel_sheet = excel_app
            End If
        
            ' Open the Access database.    
            ' Get data from the Excel spreadsheet and insert
            ' it into the TestValues table.
            row = 1
            Dim ii As Integer
            For i = 1 To 200
                ' Get the next value.
                LB1.AddItem " "
                For ii = 1 To 12
                    new_value = Trim$(excel_sheet.Cells(row, ii))
                    LB1.TextMatrix(i, ii) = new_value
                Next ii
                ' See if it's blank.
                
        
                ' Insert the value into the database.
                
        
                row = row + 1
            Next i
        
            ' Close the database.        ' Comment the rest of the lines to keep
            ' Excel running so you can see it.
        
            ' Close the workbook without saving.
            excel_app.ActiveWorkbook.Close False
        
            ' Close Excel.
            excel_app.Quit
            Set excel_sheet = Nothing
            Set excel_app = Nothing
            Exit Sub
    NoExl:
          MsgBox "对不起,无法导入Excel文件,请您确认您的电脑中已安装 Ms Office Excel 软件。"
    End Sub