|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 多文件合并复杂()
k = 1
Filename = Application.GetOpenFilename
b = VBA.InStrRev(Filename, "\")
folder = Left(Filename, b)
a = Dir(folder)
Do While a <> ""
Set wb = Workbooks.Open(folder & a)
m = wb.Worksheets(1).Cells(1, Columns.Row).End(xlToRight).Column
If Workbooks("工作簿1").Worksheets.Count < m Then
Workbooks("工作簿1").Worksheets.Add , Count:=m - 1
End If
For i = 1 To m
wb.Worksheets(1).Columns(i).Copy Workbooks("工作簿1").Worksheets(i).Cells(1, k)
Next
wb.Close
a = Dir
k = k + 1
Loop
End Sub |
|