Do Until rs.EOF
If rs.Fields("TABLE_TYPE") = "TABLE" Then
s = Replace(rs("TABLE_NAME").Value, "'", "")
If Right(s, 1) = "$" Then
SQL = "select 物品,型号,数量 from [" & s & "] where 物品 is not null"
On Error Resume Next
Set rst = cnn.Execute(SQL)
If Err.Number = -2147217904 Then GoTo next0
On Error GoTo 0
If Not rst.EOF Then
arr = rst.GetRows()
For i = 0 To UBound(arr, 2)
c = Split(Filepath(x), "\")
m = m + 1
For j = 1 To 3
If Right(Filepath(x), 4) = ".xls" Then
If InStr(Filepath(x), "\") Then
brr(m, -2) = c(0)
brr(m, -1) = Left(c(1), Len(c(1)) - 4)
Else
brr(m, -2) = a(UBound(a))
brr(m, -1) = Left(Filepath(x), Len(Filepath(x)) - 4)
End If
Else
If InStr(Filepath(x), "\") Then
brr(m, -2) = c(0)
brr(m, -1) = Left(c(1), Len(c(1)) - 5)
Else
brr(m, -2) = a(UBound(a))
brr(m, -1) = Left(Filepath(x), Len(Filepath(x)) - 5)
End If
End If
brr(m, 0) = Replace(Replace(s, "$", ""), "'", "")
brr(m, j) = arr(j - 1, i)
Next
Next
End If
End If
End If
next0:
rs.MoveNext
Loop
加几行容错就可以了。
文件夹名,工作薄名,工作表名,都可以写进 Sql语句的。
比如:
SELECT Mypath AS 文件夹名,Filepath(x) AS 工作薄名, s AS 工作表名,* FROM [S$] |