excel文件打开乱码 excel文件打不开( 二 )


    Dim fileCount As Integer, maxRow As Integer
    Dim iRow As Integer, iCol As Integer
    Dim sFile As String
    
    Set ws = ThisWorkbook.Sheets(1)
    Dim sht As Worksheet
    
    '清空历史内容,防重复
    ws.Cells.ClearContents
    Application.ScreenUpdating = False
    If sPath <> "" Then
        sPath = sPath & "\\"
        sFile = Dir(sPath & "*.xls?")
        Do While Len(sFile) > 0
            fileCount = fileCount + 1
            Set wb = Workbooks.Open(sPath & sFile)
            Set sht = wb.Sheets(1)
            '数据的行列数
            With sht.Range("a1").CurrentRegion
                iRow = .Rows.Count
                iCol = .Columns.Count
            End With
            
            If ws.Range("a1") = "" Then '第一次粘贴
                ws.Range("a1").Resize(iRow, iCol).Value = https://atx106.com/_
                sht.Range("a1").CurrentRegion.Value
            Else
                maxRow = ws.Cells(Rows.Count, 1).End(3).Row + 1
                ws.Cells(maxRow, 1).Resize(iRow – 1, iCol).Value = https://atx106.com/_
                sht.Range("a2").Resize(iRow – 1, iCol).Value
            End If
            wb.Close 0
            sFile = Dir
        Loop
    End If
    Application.ScreenUpdating = True
    MsgBox "合并完成,共合并" & fileCount & "个文件", vbOKOnly, "提示"
End Sub
说完VBA,我们最后再来说一下,Power Query如何实现汇总,我知道很多新手朋友都是一步一步操作,这里我们就直接使用M函数来写,所谓的函数式编程:

excel文件打开乱码 excel文件打不开


Excel办公实战 一起学习Excel,0基础、进阶、高级图文动画教程!技巧,函数,技巧,VBA,可视化图表,PBI!视频教程、免费模板、精英培训!VLOOKUP系列教程! 1107篇原创内容
▲1000+精心原创,您有问题,这里有方案

推荐阅读