|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 合并多薄首表不连续单元格()
Dim Fso As Object, File As Object, cnn As Object, rs As Object, SQL$, m&, arr()
Set Fso = CreateObject("Scripting.FileSystemObject")
ReDim arr(1 To Fso.GetFolder(ThisWorkbook.Path).Files.Count, 1 To 13)
For Each File In Fso.GetFolder(ThisWorkbook.Path).Files
If File.Name Like "*.xlsx" Then
m = m + 1
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.ace.OLEDB.12.0;Extended Properties='Excel 12.0;hdr=no';Data Source=" & File
arr(m, 1) = Split(File.Name, ".")(0)
Set rs = cnn.Execute("SELECT * FROM [$G9:G9]")
arr(m, 2) = rs.Fields(0)
' Set rs = cnn.Execute("SELECT LAST(F2) FROM [Sheet1$A1:B100] ")
' arr(m, 3) = rs.Fields(0)
' Set rs = cnn.Execute("SELECT F2 FROM [Sheet1$A1:B100] WHERE F1 LIKE '%" & Split(Cells(1, 4), "/")(2) & "'")
' arr(m, 4) = rs.Fields(0)
End If
Next
ActiveSheet.UsedRange.Offset(1).ClearContents
If m > 0 Then [a2].Resize(m, 13) = arr
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
Set Fso = Nothing
End Sub
'http://club.excelhome.net/forum.php?mod=viewthread&tid=1221645 |
|