我一直在尝试从一个工作簿中的特定单元格中复制数据,然后将其粘贴到另一个工作簿中。
我尝试过在网上找到的六个代码,很多来自本网站。无论我尝试哪种代码,我都会收到1004 error: unable to find file
错误消息。
我正在尝试的最新代码是
Sub COPYCELL()
Dim wbk As Workbook
strFirstFile = "c:\test\tugboat.xlsx\"
strSecondFile = "c:\test\zzzzmaster.xlsm\"
Set wbk = Workbooks.Open(strFirstFile)
With wbk.Sheets("Sheet1")
Range("A3").Copy
End With
Set wbk = Workbooks.Open(strSecondFile)
With wbk.Sheets("Sheet1")
Range("A3").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
End With
End Sub
Here is an image of the file properties, just to verify that I'm not doing something stupid. 我知道你们经常会得到这个问题,但我找不到任何可以解决这个问题的方法。如果有人可以伸出援助之手,我将不胜感激。
答案 0 :(得分:0)
如果您从zzzzmaster.xlsm运行宏,则可以缩短代码
Dim wbk As Workbook
strFirstFile = "c:\test\tugboat.xlsx"
Set wbk = Workbooks.Open(strFirstFile)
ThisWorkbook.Sheets("Sheet1").Range("A3").Value = wkb.Sheets(Sheet1).Range("A3").Value
如果从第三个工作簿运行宏
Dim wbk As Workbook
Dim wbk2 As Workbook
strFirstFile = "c:\test\tugboat.xlsx"
strSecondFile = "c:\test\zzzzmaster.xlsm"
Set wbk = Workbooks.Open(strFirstFile)
Set wbk2 = Workbooks.Open(strSecondFile)
wkb2.Sheets("Sheet1").Range("A3").Value = wkb.Sheets(Sheet1).Range("A3").Value