gpt4 book ai didi

excel - 在 Excel 2007 中将多个图表复制为图片会出现应用程序定义的错误

转载 作者:行者123 更新时间:2023-12-02 11:33:09 24 4
gpt4 key购买 nike

简介

我似乎无法让 ChartObjects.CopyPicture 方法在 Excel 2007 中工作。无论我尝试什么,我都会收到错误。

使用此技术会在 CopyPicture 行上引发“应用程序定义或对象定义的错误”。

ActiveSheet.ChartObjects.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Sheets("Sheet2").Paste

此方法在 PasteSpecial 行上抛出“Worksheet 类的 PasteSpecial 方法失败”

ActiveSheet.ChartObjects.Copy    
Sheets("Sheet2").PasteSpecial Format:="Picture (Enhanced Metafile)", Link:=False, DisplayAsIcon:=False

但是,如果我使用图表作为 Shape 对象,它就可以工作。

ActiveSheet.Shapes("Chart 6").CopyPicture Appearance:=xlScreen, Format:=xlPicture
Sheets("Sheet2").Paste

这也有效

ActiveSheet.Shapes("Chart 6").Copy
Sheets("Sheet2").PasteSpecial Format:="Picture (Enhanced Metafile)", Link:=False, DisplayAsIcon:=False

问题

我的问题是,当我尝试将多个图表复制为一组时,会失败。

我尝试使用 Shapes 对象的 Range 属性,但没有可用的 CopyPicture 方法。我想出了这个解决方法,但这也失败了,并显示与我尝试复制图片时收到的相同消息。

ActiveSheet.Shapes.Range(Array("Chart 5", "Chart 6")).Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Sheets("Sheet2").Paste

相反,这也不起作用

ActiveSheet.Shapes.Range(Array("Chart 5", "Chart 6")).Select
Selection.Copy
Sheets("Sheet2").PasteSpecial Format:="Picture (Enhanced Metafile)", Link:=False, DisplayAsIcon:=False

最佳答案

这个问题已经让我抓狂很久了。我终于找到了一个可行的解决方案,希望这能在将来帮助其他人。

基本上,解决方案是将图表分组为单个 Shape 对象,然后在该形状上复制图片,然后在完成后取消分组。

With ActiveSheet.ChartObjects.ShapeRange.Group
.CopyPicture Appearance:=xlScreen, Format:=xlPicture
.Ungroup
End With

Sheets("Sheet2").Paste

关于excel - 在 Excel 2007 中将多个图表复制为图片会出现应用程序定义的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/687353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com