|
楼主 |
发表于 2017-2-17 16:09
|
显示全部楼层
本帖最后由 lsc900707 于 2017-2-17 16:12 编辑
修改VBA语句 关于合并工作表的列数的变动
http://club.excelhome.net/thread-1328390-1-1.html
(出处: ExcelHome技术论坛)
Sub HzWb()
Dim bt As Range, r As Long
r = 1
Dim wt As Worksheet
Set wt = ThisWorkbook.Worksheets(1)
wt.Rows(r + 1 & ":1048576").ClearContents
Application.ScreenUpdating = False
Dim FileName As String, sht As Worksheet, wb As Workbook
Dim Erow As Long, fn As String, arr As Variant
FileName = Dir(ThisWorkbook.Path & "\*.xlsx")
Do While FileName <> ""
If FileName <> ThisWorkbook.Name Then
Erow = wt.Range("A1").CurrentRegion.Rows.Count + 1
fn = ThisWorkbook.Path & "\" & FileName
Set wb = GetObject(fn)
Set sht = wb.Worksheets(1)
arr = sht.Range(sht.Cells(r + 1, "A"), sht.Cells(1048576, "J").End(xlUp).Offset(0, 1))
wt.Cells(Erow, "A").Resize(UBound(arr, 1), UBound(arr, 2)) = arr
wb.Close False
End If
FileName = Dir
Loop
Application.ScreenUpdating = True
End Sub |
评分
-
1
查看全部评分
-
|