我正在尝试创建一个简单的宏来将数据从关闭的 Excel 文件复制到我打开的当前文件中。到目前为止,我已经创建了这个
Sub CopyData()
Dim path As String
path = "C:\Users\sam\Coding\bk.xlsx"
Dim currentWb As Workbook
Set currentWb = ThisWorkbook
Dim openWb As Workbook
Set openWb = Workbooks.Open(path)
Dim openWs As Worksheet
Set openWs = openWb.Sheets("Sheet1")
currentWb.Activate
openWb.Activate
openWs.Range("A1:C2").Copy
currentWb.Range("A1").PasteSpecial
openWb.Close (False)
End Sub
但我得到一个运行时错误 438,在调试时它突出显示行“currentWb.Range("A1").PasteSpecial”。我到处搜索以找到答案,但我没有成功。我的问题是,我错过了什么?
先感谢您!