如何合并多个excel文件?
操作方法
- 01
在存放文件的目录之外打开一个空的Excel文档 运行下面分宏:(注意文件目录) Sub cfl() Dim fs, f, f1, fc, s, x Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder("e:\test\") '存放文件的目录 Set fc = f.Files For Each f1 In fc If Right(f1.Name, 3) = "xls" Then x = x + 1 Workbooks.Open (f1.Path) For i = 1 To 255 Workbooks(1).Sheets(1).Cells(x, i).Value = _ Workbooks(2).Sheets(1).Cells(1, i).Value Next Workbooks(2).Close savechanges:=False End If Next End Sub
赞 (0)