1
我試圖將文件夾中的所有文件的值粘貼到主文件夾,但我在粘貼過程中不斷收到錯誤。這是我的代碼:如何將特殊從多個工作簿粘貼到主工作簿
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
請問我能得到一些幫助嗎?
感謝您的回答。不幸的是,我現在在該行出現錯誤1004。你知道那可能是什麼嗎? –
什麼是實際的錯誤_message_? –
該消息是瑞典語,但表示類似於錯誤1004:程序或對象定義的錯誤。 –