本文总共616个字,阅读需3分钟,全文加载时间:2.309s,本站综合其他专栏收录该内容! 字体大小:

文章导读:Excel快速合并表格代码(仅限于office) 多个Excel表格合并为一张工作表 在Excel界面按住alt+f11-视图-代码窗口-复制粘贴-运行 Sub sheets2one()   ‘定义对话框变量   Dim cc As FileDialog   Set cc = Ap……各位看官请向下阅读:

Excel快速合并表格代码(仅限于office)

多个Excel表格合并为一张工作表

在Excel界面按住alt+f11-视图-代码窗口-复制粘贴-运行

Sub sheets2one()

  ‘定义对话框变量

  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

以上内容由优质教程资源合作伙伴 “鲸鱼办公” 整理编辑,如果对您有帮助欢迎转发分享!

你可能对这些文章感兴趣:

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注