我想将文件位置在单元格I4,I5上声明的数据复制到文件位置在单元格B4,B5上声明的文件。数据应该从一个工作簿复制到另一工作簿,但是它显示了运行时错误“ 9”。有人知道出什么问题吗?
Sub foo()
Dim x As Workbook
Dim y As Workbook
Dim FileName As String
Dim FilePath As String
Dim PFile As String
Dim PFilePath As String
FilePath = Worksheets("Sheet1").Range("B4")
FileName = Worksheets("Sheet1").Range("B5")
PFilePath = Worksheets("Sheet1").Range("I4")
PFile = Worksheets("Sheet1").Range("I5")
'## Open both workbooks first:
Set x = Workbooks.Open(PFilePath & PFile)
Set y = Workbooks.Open(FilePath & FileName)
'Now, copy what you want from x:
x.Sheets("DTH&TPDClaims List").Range("A1:W9999").Copy
'Now, paste to y worksheet:
y.Sheets("DTH&TPDClaims List").Range("A1:W9999").PasteSpecial
End Sub