大神给你来段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
能给点解释吗?谢谢
微信号即用户名。
广告 您可能关注的内容 |