美文网首页
Excel技巧之合并工作簿-单表

Excel技巧之合并工作簿-单表

作者: 蔡龙生 | 来源:发表于2020-07-28 10:22 被阅读0次

    运行环境,excel的vba,开启方法自行百度
    合并条件,每个文件合并第一个表,用文件名命名表名
    Sub 合并工作簿单()
    Dim str As String
    Dim wb As Workbook
    Dim lj As String
    lj = InputBox("请输入文件路径,格式c:\a")
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    str = Dir(lj & "*.xls*")
    For i = 1 To 100
    Set wb = Workbooks.Open(lj & "" & str)
    Application.DisplayAlerts = False
    wb.Sheets(1).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
    ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = Split(wb.Name, ".")(0)
    wb.Close
    str = Dir
    If str = "" Then
    Exit For
    End If
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    Next
    End Sub

    Sub 合并工作簿单()
    Dim str As String
    Dim wb As Workbook
    Dim lj As String
    lj = InputBox("请输入文件路径,格式c:\a")
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    str = Dir(lj & "\*.xls*")
    For i = 1 To 100
    Set wb = Workbooks.Open(lj & "\" & str)
    Application.DisplayAlerts = False
    wb.Sheets(1).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
    ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = Split(wb.Name, ".")(0)
    wb.Close
    str = Dir
    If str = "" Then
    Exit For
    End If
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    Next
    End Sub
    

    相关文章

      网友评论

          本文标题:Excel技巧之合并工作簿-单表

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