Paste all charts in WORKBOOK into powerpoint

vbaNewby

Board Regular
Joined
Jan 26, 2011
Messages
138
Hello,

I found this nifty piece of code that will paste all the charts from the active worksheet into a new powerpoint slide, one slide per chart . I would like to adapt this to paste every chart from the active workbook (including every worksheet)


Code:
For iCht = 1 To ActiveSheet.ChartObjects.Count
    ' copy chart as a picture
    ActiveSheet.ChartObjects(iCht).Chart.CopyPicture _
        Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture

    ' Add a new slide and paste in the chart
    SlideCount = PPPres.Slides.Count
    Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutBlank)
    PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
    With PPSlide
        ' paste and select the chart picture
        .Shapes.Paste.Select
        ' align the chart
        PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
        PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
    End With

Next

http://peltiertech.com/Excel/XL_PPT.html#chartsslides

Any help with doing so? I've tried the following:

Code:
   For Cht = 1 To ActiveWorkbook.Charts.count
    ' copy chart as a picture
    ActiveWorkbook.Charts(Cht).Chart.CopyPicture _
        Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture

    ' Add a new slide and paste in the chart
    SlideCount = PP.Slides.count
    Set PS = PP.Slides.Add(SlideCount + 1, ppLayoutBlank)
    PA.ActiveWindow.View.GotoSlide PS.SlideIndex
    With PS
        ' paste and select the chart picture
        .Shapes.Paste.Select
        ' align the chart
        PA.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
        PA.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
    End With

Next

ActiveWorkbook.Charts.count is returning a count of zero, there are a bunch of charts in my workbook however.

Any help appreciated!

</pre>
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Nevermind, found my solution right after I posted. You have to loop thru each worksheet and then loop through each chart. ;) Cheers!

Code:
  For Each ws In ActiveWorkbook.Worksheets
     For Each coChart In ws.ChartObjects
    ' copy chart as a picture
    coChart.CopyPicture '_
    ' Add a new slide and paste in the chart
    SlideCount = PP.Slides.count
    Set PS = PP.Slides.Add(SlideCount + 1, ppLayoutBlank)
    PA.ActiveWindow.View.GotoSlide PS.SlideIndex
    With PS
        ' paste and select the chart picture
        .Shapes.Paste.Select
        ' align the chart
        PA.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
        PA.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
    End With
    Next
Next
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,874
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top