PasteSpecial不起作用 [英] PasteSpecial don't works

查看:69
本文介绍了PasteSpecial不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是疯狂地发现这个错误:运行时错误1004 - 此对象的粘贴特殊方法无法执行



这是我的代码:

I'm getting totaly crazy with this error: Runtime error 1004 - The Paste-Special method of this object can't be executed

This is my code:

If TypeName(cb) Like "CheckBox" Then
                    If cb.Value = True Then
                        Worksheets(ReiternameAttribute).Cells(header - 1,3).Copy
                        Selection.Offset(0, 1).Select
                        With Selection
                            .Borders.LineStyle = xlContinuous
                            .Value = cb.Caption
                            .PasteSpecial Paste:=xlFormats
                        End With
                    End If
End If





如果我通过使用F8的代码,我得到了行.PasteSpecial中的错误。

但是当我切换到excel-sheet时,选择了正确的单元格。我也尝试了这个并得到了同样的错误:



if i go through the code with F8, I get the error in the line .PasteSpecial.
But when I switch to the excel-sheet, the right cell is selected. I also tried this and got the same error:

Range("A1:A2").Copy
Range("A31:A32").PasteSpecial

推荐答案

根据您的代码,我会说在设置边框时选择会丢失。因此,当您点击PasteSpecial调用时没有什么要粘贴。



而不是

Based on your code I'd say that the selection is lost when you set the borders. Because of that there's nothing to paste when you hit the PasteSpecial call.

Instead of
With Selection
    .Borders.LineStyle = xlContinuous
    .Value = cb.Caption
    .PasteSpecial Paste:=xlFormats
End With



尝试会发生什么使用


try what happens with

With Selection
    .PasteSpecial Paste:=xlFormats
    .Borders.LineStyle = xlContinuous
    .Value = cb.Caption
End With


这篇关于PasteSpecial不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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