我正在尝试复制Book1 Sheet1中作为对象的Chart1,并将其粘贴为Book2 Sheet1中的增强图元文件图片。我从其他网站获得此代码,但它不起作用:
'Book1 and Book2 previously declared as Workbooks and set
Book1.Sheets(1).ChartObjects(1).CopyPicture
Book2.Sheets(1).Range("B3").Paste
我得到运行时错误438:“对象不支持此属性或方法”
我会使用something like this,但他们的代码会引用图表位置,如果可能的话我想按图表编号。
更新
我已将代码修改为以下内容:
'Sheet1 and Sheet2 declared and set as Worksheets
Sheet1.ChartObjects(1).Chart.CopyPicture
Sheet2.PasteSpecial Format:="Picture (Enhanced Metafile)", _
Link:=False, DisplayAsIcon:=False
With Sheet2.Shapes(Sheet2.Shapes.Count)
.Top = Sheet2.Range("B3").Top
.Left = Sheet2.Range("B3").Left
End With
但它现在返回运行时错误1004:“对象'_Worksheet'的方法'PasteSpecial'失败”。
答案 0 :(得分:3)
例如:
Sheet1.ChartObjects(1).CopyPicture
Sheet1.PasteSpecial _
Format:="Picture (Enhanced Metafile)", _
Link:=False, DisplayAsIcon:=False
With Sheet1.Shapes(Sheet1.Shapes.Count)
.Top = Sheet1.Range("B3").Top
.Left = Sheet1.Range("B3").Left
End With