vba 错误 1004:Microsoft Excel 无法粘贴数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14792868/
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
Error 1004: Microsoft Excel cannot paste the data
提问by JumboFive
I am having trouble copying and pasting some excel charts as pictures and recieving the error: "1004 "Microsoft Excel cannot paste the data." My code finds a premade chart, updates the range, copies the chart, and pastes it into another sheet. The weird thing is that this error is inconsistent where sometimes it will paste a certain chart as a picture and sometimes it won't. I can use similiar code to copy to word with no problems, and if I use the basic copy function, it can repaste as a chart.
我无法将某些 Excel 图表复制和粘贴为图片并收到错误:“1004”Microsoft Excel 无法粘贴数据。我的代码找到一个预制图表,更新范围,复制图表,然后将其粘贴到另一个工作表中。奇怪的是,这个错误是不一致的,有时会把某个图表粘贴为图片,有时则不会。我可以使用类似的代码复制到word没有问题,如果我使用基本的复制功能,它可以重新制作成图表。
This is the functions I am using to copy a chart and paste as a picture:
这是我用来复制图表并粘贴为图片的功能:
chtObj.CopyPicture xlScreen, xlPicture
PasteSheet.Paste
If there is something obvious I am missing or if there any work arounds I am open to ideas
如果我遗漏了一些明显的东西,或者如果有任何变通办法,我愿意接受想法
Thank you
谢谢
回答by JumboFive
I have found that for very large points of data it is very easy for excel to lose reference to those points. So if you copy and paste a picture I believe it still in some way keeps a link to those data points which then could be volatile and cause the 1004 error to pop up. My Work around with the help of Floris, chuff, and other SO members was to copy the chartArea and paste using the pastespecial method
我发现对于非常大的数据点,excel 很容易丢失对这些点的引用。因此,如果您复制并粘贴图片,我相信它仍会以某种方式保留指向这些数据点的链接,这些数据点可能会不稳定并导致 1004 错误弹出。在 Floris、chuff 和其他 SO 成员的帮助下,我的工作是复制图表区域并使用 pastespecial 方法粘贴
ActiveSheet.ChartObjects(chtName).Activate
ActiveChart.ChartArea.Copy
PasteSheet.Select
PasteSheet.PasteSpecial Format:="Bitmap", Link:=False, DisplayAsIcon:=False
Unfortunately it seems the only way to paste to another sheet using pastespecial formatted to bitmap is to select the sheet first paste then re-select the sheet you copied from.
不幸的是,似乎使用pastespecial 格式粘贴到另一个工作表的唯一方法是先选择工作表粘贴,然后重新选择从中复制的工作表。
回答by Rosary Girl
The only thing that worked for me was Paste Special then "XML Spreadsheet". It preserved the integrity of the spreadsheet with my dates and dollar amounts and links to websites.
唯一对我有用的是粘贴特殊然后“XML 电子表格”。它保留了电子表格的完整性,包括我的日期和美元金额以及网站链接。