|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub ADO_多薄首表_合并_无标题行()
Range("A2:Z1048576") = ""
Set conn = CreateObject("adodb.connection")
Path = ThisWorkbook.Path
n = UBound(Split(Path, "\"))
sPath = Replace(Path, Split(Path, "\")(n), "源数据/")
Fn = Dir(sPath & "*.xls?")
Set Rst = VBA.CreateObject("ADODB.Recordset")
Application.ScreenUpdating = False
Do While Len(Fn)
If InStr(Fn, "0030") = 0 And InStr(Fn, "test") = 0 Then
sConnect = "Provider=Microsoft.ACE.OLEDB.12.0;extended Properties='excel 12.0;HDR=no';data source=" & sPath & Fn
SQL = "Select F2 from [A:B] Where f1='" & Split(ThisWorkbook.Name, ".")(0) & "'"
Rst.Open SQL, sConnect, 3, 1
If Not (Rst.BOF And Rst.EOF) Then
Set Rng = Cells(Rows.Count, 2).End(3).Offset(1)
Rng.CopyFromRecordset Rst
Rng.Offset(, -1).Resize(Rst.RecordCount) = "'" & Split(Fn, ".")(0)
End If
Rst.Close
End If
Fn = Dir()
Loop
Application.ScreenUpdating = True
Set Rst = Nothing
Set Rng = Nothing
End Sub
Sub 批量复制文件() ''代码在另一工作薄中使用
Path = ThisWorkbook.Path
For h = 2 To 100
FileCopy Path & "\A1.xlsm", Path & "\" & "A" & h & ".xlsm"
Next h
End Sub
|
评分
-
1
查看全部评分
-
|