[英]Copying of a cell value from one workbook to another
Team, 球队,
Am new to excel Macro and trying to copy a value of a Cell E15 from a workbook name september to D15 of another workbook name format and am unable to do that with the below coding. 是Excel Macro的新手,它试图将单元格E15的值从9月的工作簿名称复制到另一种工作簿名称格式的D15中,并且无法使用下面的代码来实现。 Please help me
请帮我
I used the below coding to do so. 我使用下面的代码来做到这一点。
Sub COPYCELL()
Dim wbk As Workbook
strFirstFile = "c:\documents and Settings\msivas\Desktop\James\September.xls"
strSecondFile = "c:\documents and Settings\msivas\Desktop\James\Format.xls"
Set wbk = Workbooks.Open(strFirstFile)
With wbk.Sheets("Summary")
Range("E15").Copy
End With
Set wbk = Workbooks.Open(strSecondFile)
With wbk.Sheets("sheet1")
Range("D12").PasteSpecial Paste:=xlPasteAll
End With
End Sub
Am receiving an error and unable to know. 正在接收错误,无法得知。
try this update. 试试这个更新。 By not recycling the wbk variable, you will avoid issues.
通过不回收wbk变量,可以避免问题。
Sub COPYCELL()
Dim wbkOrg As Workbook, wbkDest as workbook
dim strFirstFile as string, strSecondFile as string
strFirstFile = "c:\documents and Settings\msivas\Desktop\James\September.xls"
strSecondFile = "c:\documents and Settings\msivas\Desktop\James\Format.xls"
Set wbkOrg = Workbooks.Open(strFirstFile)
Set wbkDest = Workbooks.Open(strSecondFile)
wbkOrg.Sheets("Summary").Range("E15").Copy wbkDest.Sheets("sheet1").Range("D12")
End Sub
As per my comment, this works for me: 根据我的评论,这对我有用:
Option Explicit
Sub COPYCELL()
Dim wbk1 As Workbook, wbk2 As Workbook
Dim strFirstfile As String, strSecondFile As String
strFirstfile = "c:\documents and Settings\msivas\Desktop\James\September.xls"
strSecondFile = "c:\documents and Settings\msivas\Desktop\James\Format.xls"
Set wbk1 = Workbooks.Open(strFirstfile)
Set wbk2 = Workbooks.Open(strSecondFile)
With wbk1.Sheets("Summary")
.Range("E15").Copy
End With
With wbk2.Sheets("sheet1")
.Range("D12").PasteSpecial Paste:=xlPasteAll
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.