搜档网
当前位置:搜档网 › 批量将多个excel中的多个工作簿合并到一个excel中

批量将多个excel中的多个工作簿合并到一个excel中

批量将多个excel中的多个工作簿合并到一个excel中
批量将多个excel中的多个工作簿合并到一个excel中

批量将多个excel中的多个工作簿合并到一个excel中,形成多个工作薄1. 将要合并的excel放到一个文件夹中,在这个目录中新建一个excel。

2. 打开新建的excel。

3. 按alt+F11.

4. 插入一个模块。

5. 将下面的东东复制进去。

Sub CombineFiles()

Dim path As String

Dim FileName As String

Dim LastCell As Range

Dim Wkb As Workbook

Dim WS As Worksheet

Dim ThisWB As String

Dim MyDir As String

MyDir = ThisWorkbook.path & "\"

'ChDrive Left(MyDir, 1) 'find all the excel files

'ChDir MyDir

'Match = Dir$("")

ThisWB = https://www.sodocs.net/doc/f87354978.html,

Application.EnableEvents = False

Application.ScreenUpdating = False

path = MyDir

FileName = Dir(path & "\*.xls", vbNormal)

Do Until FileName = ""

If FileName <> ThisWB Then

Set Wkb = Workbooks.Open(FileName:=path & "\" & FileName)

For Each WS In Wkb.Worksheets

Set LastCell = WS.Cells.SpecialCells(xlCellTypeLastCell)

If LastCell.Value = "" And LastCell.Address = Range("$A$1").Address Then

Else

WS.Copy

After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)

End If

Next WS

Wkb.Close False

End If

FileName = Dir()

Loop

Application.EnableEvents = True

Application.ScreenUpdating = True

Set Wkb = Nothing

Set LastCell = Nothing

End Sub

6. 点击运行。

相关主题