在红色的代码出错,如何解决红色的代码的问题?谢谢。
以下代码的Set放入(vs2010)的代码区后,会自动消除。
以下代码的意图是希望一个一个数据取出,但必须用ADO读取Excel。
Dim cnn As Object, rs As Object, s As String, m As Integer
Dim sql As String, arr(8, 1) As String
Set cnn = CreateObject("ADODB.Connection")
cnn.Open ("provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;hdr=no;imex=1';data source=" & "f:\book1.xls")
sql = "select * from [Sheet1$c3:d9]"
Set rs = cnn.Execute(sql)
Do While Not rs.EOF
For i = 0 To 1
' If Len(rs.Fields(i)) <> 0 Then
' arr(m, i) = rs.Fields(i)
If Len(rs.Fields(i).value) '以上两行红色代码改为以下两行即可
arr(m, i) = rs.Fields(i).value
Else
arr(m, i) = ""
End If
Next
m = m + 1
rs.MoveNext
Loop
cnn.Close
Set cnn = Nothing
Set rs = Nothing
For i = 0 To 8
s = s & arr(i, 0) & " " & arr(i, 1) & Chr(10)
Next
MsgBox (s)
只有本站会员才能查看附件,请 登录
[此贴子已经被作者于2017-6-26 21:26编辑过]