不懂编程,代码给你也很难读懂.还是先学一点编程吧.
用ado对象,连接到excel表,下面的代码给你参考:
哦,使用前要先引用ado对象哦
Private Sub Command3_Click()
Dim Conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim sql As String
'On Error Resume Next
strName = App.Path & "\book.xls" 'EXCEL文件名
strSheetName = "sheet1" 'EXCEL表名
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & strName & ";Extended Properties='Excel 8.0;HDR=Yes'" '连接EXCEL文件
sql = "select * from [" & strSheetName & "$]" '打开EXCEL表
rs.Open sql, Conn, 3, 3
MsgBox rs.RecordCount '显示表里的记录数
Do Until rs.EOF
For i = 0 To rs.Fields.Count - 1 '读一行数据
List1.AddItem rs.Fields.Item(i).Name '读出数据,添加到list1里
If Not IsNull(rs.Fields.Item(i).Value) Then
List2.AddItem rs.Fields.Item(i).Value
Else
rs.Update
rs.Fields.Item(i).Value = i ' "peter" & i
rs.Update
End If
Next i
rs.MoveNext
Loop
rs.Close '关闭数据集
Conn.Close '关闭对象
End Sub
这个太简单了,不用跪的
就是用OLE连接EXCEL,然后操纵EXCEL读取数据