vba Excel:粘贴为文本的简单宏返回错误 1004:无法运行工作表类的粘贴方法

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

Excel: simple macro to paste as text returns error 1004: Could not run the paste method of worksheet class

excelvba

提问by Troglo

When I try to copy any text from another application to a cell in Excel 2010 (Win 7 64bits) using this macro:

当我尝试使用此宏将任何文本从另一个应用程序复制到 Excel 2010(Win 7 64 位)中的单元格时:

ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False

I get this error: Error 1004 Could not run the paste method of worksheet class

我收到此错误: 错误 1004 无法运行工作表类的粘贴方法

Looks like that line works fine for everybody else and some similar questions over here but none of the answers works for me

看起来这条线对其他人和这里的一些类似问题都适用,但没有一个答案对我有用

Any idea? Thanks

任何的想法?谢谢

回答by Kazimierz Jawor

Formatparameter for .PasteSpecialmethod seems to be sensitive to application national/language settings. If you run English version of Excel than you would call this method this way (as in your question):

Format.PasteSpecial方法的参数似乎对应用程序的国家/语言设置很敏感。如果您运行英文版的 Excel,那么您会以这种方式调用此方法(如您的问题):

ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False

I'm running Polish version of Excel and the line above gives me Error 1004. But changing 'Text' into Polish 'Tekst' solve this problem:

我正在运行波兰语版本的 Excel,上面的行给了我错误 1004。但是将“文本”更改为波兰语“Tekst”解决了这个问题:

ActiveSheet.PasteSpecial Format:="Tekst", Link:=False, DisplayAsIcon:=False

If any of you doesn't know how to solve similar problem best option is to record (with macro recorder) this simple Paste Specialoperation.

如果你们中的任何人不知道如何解决类似的问题,最好的选择是记录(使用宏记录器)这个简单的Paste Special操作。