0
大家好!
我有一个包含文件的目录。 每个文件都有一个工作表。 我需要将指定的行(例如G:G)从每个文件复制到一个master_file.xlsx(从我开始我的宏)。
其中一个问题是行很大(约为2000个值),所以我的代码在每次迭代时都会抛出警告:剪贴板中有大量信息。 请帮我一试。
非常感谢!
我的代码是下面:从excel文件复制数据行
子my_macros()
Dim sFileName, sNewFileName, myFile As String
sFileName = ThisWorkbook.Path & "\master_file.xlsm"
If Dir(sFileName, 16) = "" Then MsgBox "Warning", vbCritical, "Error" Exit Sub
Cells.Select
Selection.ClearContents
For i = 1 To 5
'MsgBox (i)
sNewFileName = ThisWorkbook.Path & "\file_" & i & ".xlsx"
If Dir(sNewFileName, 16) = "" Then Exit For
Application.ScreenUpdating = False
'MsgBox (sNewFileName)
Workbooks.Open sNewFileName
Range("G:G").Select
Selection.Copy
ActiveWorkbook.Close
ThisWorkbook.Activate
'Active
Worksheets("Sheet1").Columns(2).Insert Shift:=xlToRight
Application.CutCopyMode = False
'Workbooks(sNewFileName).Close SaveChanges:=False
Next i
End Sub