Error in script which copies charts from Excel to PowerPoint

前端 未结 3 1158
渐次进展
渐次进展 2021-01-16 15:24

I am attempting to call the below Sub in order to copy given chart to a specified PowerPoint presentation. However, when I run the macro which calls this Sub, the line indic

3条回答
  •  一个人的身影
    2021-01-16 15:45

    It looks like the error can be attributed to how VBA handles variables across different references. (In particular, how PPT VBA handles them.) I was able to get the macro to work by actively selecting/copying the charts. I will need to do a little more research to get why variables cause problems, but at least I know how tackle the problem.

    Sub copyChart(curSlide As Slide)
        Dim chr as ChartObject
        Set chr = Sheets("CHARTSHEET").ChartObjects(1)  
        Sheets("CHARTSHEET").Select
        ActiveChart.CopyPicture
        curSlide.Shapes.PasteSpecial
    End Sub
    

提交回复
热议问题