vb如何批量处理excel,我有1000个excel文件,要求在每个excel中提取某行到某行的数据汇总到新建的excel中

求VB代码

大神给你来段vba 例子瞧瞧,

Sub test()

    Dim xls_Folder As String

    xls_Folder = ThisWorkbook.Path & "\textxls"

    Dim xlsFiles() As String

    Dim fso, f, fc, s

    Set fso = CreateObject("Scripting.FileSystemObject")

    Set f = fso.GetFolder(xls_Folder)

    Set fc = f.Files

    s = ""

    For Each f1 In fc

        If Not StrComp(Right(f1.Name, 4), ".xls", 1) Then

            If s = "" Then

                s = f1.Name

            Else

                s = s & "|" & f1.Name

            End If

        End If

    Next

    xlsFiles = Split(s, "|")

    Dim i As Long

    Dim m As Long

    Dim n As Long

    m = LBound(xlsFiles)

    n = UBound(xlsFiles)

    Dim wb As Workbook

    Dim wsh As Worksheet

    Dim thiswsh As Worksheet

    Dim rng As Range

    Dim start_Line As Long

    Dim stop_Line As Long

    Dim thiswshlastline As Long

    Dim arr()

    start_Line = 3

    stop_Line = 10

    Set thiswsh = ThisWorkbook.Sheets("Sheet1")

    Application.ScreenUpdating = False

    On Error Resume Next

    For i = m To n

        Set wb = Workbooks.Open(xls_Folder & "\" & xlsFiles(i))

        Set wsh = wb.Worksheets("Sheet1")

        arr = wsh.Range(start_Line & ":" & start_Line, stop_Line & ":" & stop_Line)

        thiswshlastline = thiswsh.Range("A:A").Find("*", , , , xlByRows, xlPrevious).Row

        Set rng = thiswsh.Range((thiswshlastline + 1) & ":" & (thiswshlastline + 1 + stop_Line - start_Line))

        rng = arr

        Set rng = Nothing

        Set wsh = Nothing

        wb.Close

        Set wb = Nothing

    Next

    Application.ScreenUpdating = True

End Sub


追问

能给点解释吗?谢谢

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-10-30

比你更大的神直接提供实用工具!如下图所示。现在功能列表1,注意勾选提取指定区域。

第2个回答  2016-10-30
这1000个excel的名称是有规律的吧,没有规律的话不好办
第3个回答  2016-10-30
I can。
微信号即用户名。
第4个回答  2016-10-30
我可以,可以hi我
相似回答