我无法将数据从一个工作簿复制到另一个工作簿。但在同一个工作簿中可以正常运行。运行宏程序后,目标工作表为空。我有两个代码。都不起作用。我的源文件是.xlsx格式,目标文件是.xlsm格式。是否有错误?
代码1:
Sub mycode()
Workbooks.Open Filename:="source_file"
Worksheets("Sheet1").Cells.Select
Selection.Copy
Workbooks.Open Filename:="destination_file"
Worksheets("Sheet1").Cells.Select
Selection.PasteSpecial
ActiveWorkbook.Save
End Sub
代码 2
Sub foo2()
Dim x As Workbook
Dim y As Workbook
Set x = Workbooks.Open("source file")
Set y = Workbooks.Open("destination file")
y.Sheets("Sheet1").Range("A1").Value = x.Sheets("Sheet1").Range("A1")
x.Close
End Sub
On Error Resume Next
或On Error GoTo
语句? - user3598756