Sub drbg()
‘把目录下所有文件名输入表格
Dim str As String
Dim wb As Workbook
Dim sht As Worksheet
str = Dir("d:\data\*.*")
‘可以把文件名改为"*.xls*"
For i = 1 To 100
‘ range("a" &i)=s=tr
‘ workbooks.open ("d:\data\" & str)
Set wb = Workbooks.Open("d:\data\" & str)
‘这是打开所有文件
‘wb.sheets(1).copy after:=thisworkbook.sheets(thisworkbook.sheets.count)
For Each sht In wb.Sheets
sht.Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = Split(wb.Name, ".")(0) & sht.Name
Next
wb.Close
‘这是把打开的文件关闭
str = Dir
If str = "" Then
Exit For ‘如果 str为空,退出循环
End If
Next
End Sub
原文地址:https://www.cnblogs.com/yihao529/p/12297757.html
时间: 2024-10-13 17:04:28