我有 15 个 excel 文件,每个文件包含两个工作表。每个文件中,单元格 A1:A48 应从第一页复制到工作表 1 中的新文件,以便从第一个单元格复制到下一列。它只从 14 个文件中复制。15 文件打开,但单元格 A1:A48 未被复制。
Sub OpenCopyAndPasteWorkbook()
Dim directory As String, fileName As String, Sheet1 As Worksheet, i As Integer
Dim wb As Workbook
Dim wbArray(15)
Application.ScreenUpdating = False
For i = 1 To 15
wbArray(i) = ("d:\test\Book" & i)
Workbooks.Open fileName:=wbArray(i)
Workbooks(i).Worksheets("Sheet1").Range("A1:A48").Copy _
Workbooks("Book20.xlsx").Worksheets("Sheet1").Range("A1:A48").Offset(0, i)
Application.CutCopyMode = False
Next i
Application.ScreenUpdating = True
End Sub