|
2#
楼主 |
发表于 2013-7-24 19:08:52
|
只看该作者
- Sub 数据提取()
- Dim cnn As Object, cat As Object
- Dim i As Integer
- Dim Mypath As String, Myfile As String
- Dim sql As String
- Dim tb As Object
- Mypath = ThisWorkbook.Path & ""
- Myfile = Dir(Mypath & "*.xls")
- ActiveSheet.UsedRange.Offset(1).ClearContents
- Set cnn = CreateObject("adodb.connection")
- Set cat = CreateObject("ADOX.Catalog")
- cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & Mypath & Myfile
- Do While Myfile <> ""
- If Myfile <> ThisWorkbook.Name Then
- cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=No';Data Source=" & Mypath & Myfile
- For Each tb In cat.tables
- If tb.Type = "TABLE" Then
- If tb.Name = "Sheet2$" Then
- sql = "select 工号,收入 from[Excel 8.0;Database=" & Mypath & Myfile & "].[" & tb.Name & "a1:o65536]"
- [a65536].End(3).Offset(1).CopyFromRecordset cnn.Execute(sql)
- End If
- End If
- Next
- End If
- Myfile = Dir()
- Loop
- Set cat = Nothing
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码 提取得不全的。怎么改好?
|
|