vba 从一个工作簿复制并粘贴到另一个
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11029531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy and paste from one workbook to another
提问by TBone2087
I have code in one workbook, this should open another workbook, copy and paste into the workbook with the code. I can select the data but can't paste it.
我在一个工作簿中有代码,这应该打开另一个工作簿,将代码复制并粘贴到工作簿中。我可以选择数据但无法粘贴它。
I have tried many different variations of code getting errors or it doesn't do anything. An example is run in template.xls, which is where I want to paste the data:
我尝试了许多不同的代码变体,但都出现错误,或者什么也没做。在 template.xls 中运行一个示例,这是我要粘贴数据的位置:
Set dlsheet = appexcel.Workbooks.Open(strPath & "downloadedData.xls")
With dlsheet.Sheets("Data")
.range("A1:H3").Select.copy
selection.copy
End With
I don't know how to use the selection since this will copy from the template, I tried using a full stop before selection.
我不知道如何使用选择,因为这将从模板中复制,我尝试在选择前使用句号。
I can copy the entire sheet from dlsheet into a new workbook, if someone could tell me how to copy it to the template and not a new workbook then this would also do the trick.
我可以将整个工作表从 dlsheet 复制到新工作簿中,如果有人能告诉我如何将其复制到模板而不是新工作簿,那么这也可以解决问题。
dlsheet.Sheets("Data").Copy
回答by Stefan
Set dlsheet = appexcel.Workbooks.Open(strPath & "downloadedData.xls")
dlsheet.Sheets("Data").range("A1:H3").copy
ThisWorkbook.ActiveSheet.Paste Destination:=ThisWorkbook.ActiveSheet.Range( "A1:H3")
回答by Siddharth Rout
Try this
尝试这个
Set dlsheet = appexcel.Workbooks.Open(strPath & "downloadedData.xls")
With dlsheet
.Sheets("Data").Range("A1:H3").Copy
.Sheets("Data").Range("A1").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With