粘贴特殊错误1004 Range类的PasteSpecial方法失败 [英] Paste Special error 1004 PasteSpecial method of Range class failed

查看:1021
本文介绍了粘贴特殊错误1004 Range类的PasteSpecial方法失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经仔细研究了当前针对该问题的答案,但都没有解决这个问题的方法.

I have looked thoroughly at the current answers for this problem and none of them have fixed mine.

操作只是复制一张纸的一部分,然后复制到一本名为预算的新书上.

The operation is simply copying a selection of a sheet and copying to a new book called budget.

再次,我尝试了多种不同的方法来做同一件事,但似乎没有一个方法可以改变此错误. select方法有效,只有在我尝试粘贴时才会中断.

Again I have tried multiple different ways of doing the same thing and none of them seem to change this error. The select method works,it only breaks when I try to paste.

代码:

Range("B3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy

Dim wk As Workbook
Set wk = Workbooks.Add

wk.SaveAs FileName:=ThisWorkbook.path & "\" & "Budget.xlsx"
wk.Activate
wk.Unprotect
wk.Worksheets("Sheet1").Range("B3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False

谢谢

推荐答案

尝试以下代码(代码内部的注释说明):

Try the code below (explanation inside the code as comments):

Dim wk As Workbook
Set wk = Workbooks.Add

wk.SaveAs Filename:=ThisWorkbook.Path & "\" & "Budget.xlsx"
wk.Activate
wk.Unprotect

' have the Copy>>Paste section together
Dim LastCol As Long
Dim LastRow As Long

' you never mentioned which sheet to copy from, I used the first index
With ThisWorkbook.Sheets(1)
    LastCol = .Range("B3").End(xlToRight).Column
    LastRow = .Range("B3").End(xlDown).Row
    .Range("B3", .Cells(LastRow, LastCol)).Copy ' <-- Copy without Select
End With

' Paste without Select
wk.Worksheets("Sheet1").Range("B3").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False

这篇关于粘贴特殊错误1004 Range类的PasteSpecial方法失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆