Excel Pastespecial VBA

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26999946/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:18:01  来源:igfitidea点击:

Excel Pastespecial VBA

excelvbaexcel-vba

提问by Navron

I am attempting to copy the contents of a certain workbook to another. However, I indent to keep the source formatting. However, my code produces application/object not defined errors. Any help would be much appreciated.

我试图将某个工作簿的内容复制到另一个。但是,我缩进以保留源格式。但是,我的代码产生应用程序/对象未定义错误。任何帮助将非常感激。

Public Sub CommandButton1_Click()
Worksheets("Sheet1").Range("A2:D349").Copy Destination:=Worksheets("Sheet6").Range("A2")
Worksheets("Sheet1").Range("A2:D349").PasteSpecial Paste:=xlPasteFormats
End Sub

回答by Rory

There's nothing on the clipboard when you specify a destination, so you have to separate the steps:

指定目的地时剪贴板上没有任何内容,因此您必须将步骤分开:

Public Sub CommandButton1_Click()
Worksheets("Sheet1").Range("A2:D349").Copy 
Worksheets("Sheet6").Range("A2").PasteSpecial xlPasteAll
Worksheets("Sheet1").Range("A2:D349").PasteSpecial Paste:=xlPasteFormats
End Sub