|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Public sh
Sub 按钮1_Click()
Application.ScreenUpdating = False
ActiveSheet.UsedRange.ClearContents
Cells(1, 1) = "提取A1的值"
Cells(1, 2) = "提取C4的值"
Cells(1, 3) = "文件名"
Set sh = ActiveSheet
Getfd (ThisWorkbook.Path) 'ThisWorkbook.Path是当前代码文件所在路径,路径名可以根据需求修改
Application.ScreenUpdating = True
End Sub
Sub Getfd(ByVal pth)
Set Fso = CreateObject("scripting.filesystemobject")
Set ff = Fso.getfolder(pth)
For Each f In ff.Files
If InStr(Split(f.Name, ".")(UBound(Split(f.Name, "."))), "xl") > 0 Then
If InStr(f.Name, "汇总") = 0 Then
Set wb = Workbooks.Open(f)
For Each sht In wb.Sheets
sh.Cells(Rows.Count, 1).End(3).Offset(1) = sht.[a1]
sh.Cells(Rows.Count, 2).End(3).Offset(1) = sht.[c4]
sh.Cells(Rows.Count, 3).End(3).Offset(1) = f.Name
Next sht
wb.Close False
End If
End If
Next f
For Each fd In ff.subfolders
Getfd (fd)
Next fd
End Sub
|
|