美文网首页
excel多文件合并

excel多文件合并

作者: 家小狄 | 来源:发表于2017-05-28 20:55 被阅读21次

创建一宏,复制以下代码


Sub excel合并()

'定义对话框变量

Dim cc As FileDialog

Set cc = Application.FileDialog(msoFileDialogFilePicker)

Dim newwork As Workbook

Set newwork = Workbooks.Add

With cc

If .Show = -1 Then

Dim vrtSelectedItem As Variant

Dim i As Integer

i = 1

For Each vrtSelectedItem In .SelectedItems

Dim tempwb As Workbook

Set tempwb = Workbooks.Open(vrtSelectedItem)

tempwb.Worksheets(1).Copy Before:=newwork.Worksheets(i)

newwork.Worksheets(i).Name = VBA.Replace(tempwb.Name, ".xls", "")

tempwb.Close SaveChanges:=False

i = i + 1

Next vrtSelectedItem

End If

End With

Set cc = Nothing

End Sub


运行宏,即可。

相关文章

网友评论

      本文标题:excel多文件合并

      本文链接:https://www.haomeiwen.com/subject/igihfxtx.html