|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
或采用后期绑定,不需要引用Microsoft ActiveX Data Objects 2.x Library了:- Sub Macro1()
- Dim cnn As Object, rs As Object
- Dim SQL As String, d As Object, arr(), i&, l&, j&, n&, t
- Set d = CreateObject("scripting.dictionary")
- ActiveSheet.UsedRange.Offset(1).ClearContents
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" & ThisWorkbook.Path & ";Exclusive=No;"
- Set rs = CreateObject("ADODB.Recordset")
- SQL = "select * from z221801"
- rs.Open SQL, cnn, 1, 3
- Range("A2").CopyFromRecordset rs
- rs.MoveFirst
- ReDim arr(1 To rs.RecordCount, 1 To 12)
- For i = 1 To rs.RecordCount
- d(rs.Fields(0).Value) = i
- rs.MoveNext
- Next
- SQL = "select * from zj221800"
- Set rs = CreateObject("ADODB.Recordset")
- rs.Open SQL, cnn, 1, 3
- For i = 1 To rs.RecordCount Step 2
- n = 0
- For l = i To i + 1
- t = d(rs.Fields(0).Value)
- If t <> "" Then
- For j = 1 To 6
- arr(t, j + n) = rs.Fields(j).Value
- Next j
- End If
- n = n + 6
- rs.MoveNext
- Next l
- Next i
- Range("o2").Resize(UBound(arr), 12) = arr
- rs.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- End Sub
复制代码
如何将两个DBF文件导入到相应的工作薄对应的工作表中.rar
(19.38 KB, 下载次数: 26)
|
|