Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Excel 2007中将多个图表复制为图片会导致应用程序定义的错误_Excel_Vba - Fatal编程技术网

在Excel 2007中将多个图表复制为图片会导致应用程序定义的错误

在Excel 2007中将多个图表复制为图片会导致应用程序定义的错误,excel,vba,Excel,Vba,导言 我似乎无法使ChartObjects.CopyPicture方法在Excel 2007中工作。不管我怎么做,我都会出错 使用此技术会在CopyPicture行上抛出“应用程序定义或对象定义错误” ActiveSheet.ChartObjects.CopyPicture Appearance:=xlScreen, Format:=xlPicture Sheets("Sheet2").Paste 此方法在PasteSpecial行上作为“工作表类的PasteSpecial方法失败”抛出 Ac

导言

我似乎无法使ChartObjects.CopyPicture方法在Excel 2007中工作。不管我怎么做,我都会出错

使用此技术会在CopyPicture行上抛出“应用程序定义或对象定义错误”

ActiveSheet.ChartObjects.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Sheets("Sheet2").Paste
此方法在PasteSpecial行上作为“工作表类的PasteSpecial方法失败”抛出

ActiveSheet.ChartObjects.Copy    
Sheets("Sheet2").PasteSpecial Format:="Picture (Enhanced Metafile)", Link:=False, DisplayAsIcon:=False
但是,如果我将图表用作形状对象,它会起作用

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

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

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

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

Sheets("Sheet2").Paste

当我使用这个脚本时,它在xlPicture上给了我“无效的限定符”,请帮助