【发布时间】:2016-05-12 11:38:50
【问题描述】:
我正在尝试将文件夹中所有文件的值粘贴到主文件夹,但在粘贴过程中不断出现错误。这是我的代码:
Sub LoopThrough()
Dim MyFile As String
Dim erow
Dim FilePath As String
Dim DestWB As Workbook
Dim SourceWB As Workbook
Set DestWB = ThisWorkbook
FilePath = "C:\data\"
MyFile = Dir(FilePath)
Do While Len(MyFile) > 0
If MyFile = "Master.xlsm" Then
Exit Sub
End If
Set SourceWB = Workbooks.Open(FilePath & MyFile)
Workbooks.Open (FilePath & MyFile)
Range("A1:L51").Copy
DestWB.Range(Cells(erow, 1), Cells(erow, 12)).PasteSpecial xlValues
SourceWB.Close False
MyFile = Dir
Loop
End Sub
我能得到一些帮助吗?
【问题讨论】: